I have a form where users upload up to 5 images at a time. My script loops for each file and resizes them and puts on a watermark. Works great. I then want to write the path to these files in my database. How do i get the unique filename that the script gave to the images to write to the 5 fields in the table.
Here is the way it is setup now.
foreach ($_FILES["userfile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$imgfile_name = $_FILES['userfile']['name'][$key];
//This is how the filenames are done.
srand((double)microtime()*1000000);
$unique_str = md5(rand(0,9999999));
$p = strrpos($imgfile_name, "." );
$new_name = substr($imgfile_name , 0 , $p ) . $unique_str . substr($imgfile_name , $p , ( strlen($imgfile_name ) - $p ) );
$new_name = str_replace(" ","_",$new_name);
//Other things here
INSERT INTO TableName (pic1,pic2,pic3,pic4,pic5)
values ('$new_name','$new_name','$new_name','$new_name','$new_name')";
}
This writes the same 1st filename to the table. What should I do.
Thanks