I use a switch to check files for their file names during upload.
Only files with specific names may be forwarded. However, it only works if the name is fixed.
Is it possible that my switch can also accept variable names?
Here is an example.
I expect a file every day that starts with the name filesource but always ends with a new date like filesource-2023_05_20.csv. The format to be accepted would therefore be filesource-YYYY_MM_DD.csv.
Here my code actually:
switch($infoFichier['filename']){
// Here my variable filename
case 'filesource*':
$newFileName = 'filesource*.csv';
$updir = PATH.'/files/';
$updirst = PATH.'/files/depot/';
$uploadfile = $updir.'depot/'.$newFileName;
$fileName = $_FILES['fic_demande']['name'];
$fileType = $_FILES['fic_demande']['type'];
if (move_uploaded_file($_FILES['fic_demande']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.n";
header('location:depot/import.php?file='.$newFileName.'&path='.$updirst.'&type='.$fileType);
}
break;
Is there a solution that my switch could accept this fileformat?
THX in advance.
2
Answers
i have it figure out with substring. I add this before the switch :
Thanks everybody for your ideas and Help.
Can you please use this variable $newFileName to $newFileName = ‘filesource-‘.date(‘Y_m_d’).’.csv’;
Thanks