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?

Re: adding a prefix to the file name for each file uploaded.

I am short on time. I can't figure out why it will only rename the first file to $franNum_$currentDate_$currentTime_fileName and not the second, third, fourth, etc.

One of my coworkers said this:

Firstly, we need to either set the variables in the request POST or GET or keep them in the COOKIES.

The second problem is that since this are asynchronize call, the count that you are doing for 50 file limit on server side needs to happen on client side.

So I'm not quite sure how to do this as I am trying to rename each file on the fly without having the clients type in their info.

I have looked all over the web and haven't found a single thing that will work.

Re: adding a prefix to the file name for each file uploaded.

Where you ever able to find a solution to this?  I am having the same issue.

Thank you!
Chris