Hi people, I've forgotten how to do something in PHP and its driving me mad!
I'm trying to do a simple thing, upload images and save their paths to a database.
It all works fine, I just can't remember how to create a variable from a string.
Basically the variables going in to the Database are Img1, Img2, Img3, Img4.
My code below is a loop that writes out each image as they are uploaded.
How do I set the variable Img1 with the path of the file, inside the loop?
I can't do $Img1 = $uploadfile; as that will always write out $Img1 with each pass of the loop with the current image path.
I need to do something like
$Img.$b = $uploadfile;
$b++;
each time the loop runs, but I don't think $Img.$b will work.
Here is my code
Any ideas?Code:$uploadfile = $uploaddir . basename($_FILES['userfile']['name'][$i]); $ext = strtolower(substr($uploadfile,strlen($uploadfile)-3,3)); if (preg_match("/(jpg|gif|png)/",$ext)) { if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile)) { // Here I want to add the variable for each image ready to go in to a database. echo "Img".$imagenum." ".$uploadfile."<br>"; $imgset = "Img".$imagenum; echo "<img src=\"".$uploadfile."\"><br>"; $success++; $imagenum++; }![]()






Reply With Quote