Topic: adding a prefix to the file name for each file uploaded.
I am able to do this for the first file only. The rest are blank. Need some help please.
//set the franchise number
$franNumber = $_SESSION['franNumber'];
//set the date
$currentDate = $_SESSION['currentDate'];
//set current Time
$currentTime = $_SESSION['currentTime'];
$prefix = $franNumber . "_" . $currentDate . "_" . $currentTime;
// Clean the fileName for security reasons
$oldFileName = preg_replace('/[^\w\._]+/', '_', $oldFileName);
for ($i=0; $i < 51; $i++) {
//Add the fran#+_+TIMESTAMP+_oldfilename
$fileName = $prefix . "_" . $oldFileName;
// Make sure the fileName is unique but only if chunking is disabled
if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) {
$ext = strrpos($fileName, '.');
$fileName_a = substr($fileName, 0, $ext);
$fileName_b = substr($fileName, $ext);
$count = 1;
while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b))
$count++;
$fileName = $fileName_a . '_' . $count . $fileName_b;
}
}
$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
Does anyone know what I am doing wrong?