I have a photo uploader for a client. It's a simple input file button.
But they wanted to be able to add more than one picture.
So, when the client clicks the "add another picture?" button, I used javascript to clone the initial input button, and then used a counter to increase a digit in the name. I.E:
First input buttons name => name="uploaded1 "
When Client Wants Another pick => name="uploaded2 "
...Another One => name="uploaded3 "
(and so on)
now on my php side, im using this to move the file into a folder on the server and save the path in a MySQL table.
[PHP]
$target = "wherepixgo/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$pictureurl = $target;
if(move_uploade d_file($_FILES['uploaded']['tmp_name'], $target))
{
if($target=="wh erepixgo/"){
$target="";
echo '<center><br /><br /><br />';
echo "No file Uploaded.";
echo '</center>';
echo '<br><br><br>' ;
}
else {
echo '<center>';
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
echo '<br><br><br></center>';
}
}[/PHP]
That's great for when I only had one picture to upload, and it would just look for one input file button name "uploaded". Now there are going to be input files to the Nth degree. How can I tell php to look at all of the posted variables named "uploaded(# )" and loop through an inputting code til no more.
Psuedocode:
[PHP]
while(there are posted variables with the name "uploaded#" ){
find it's # at the end of its name;
upload the current photo;
copy the path name into a variable so i can save it in MySQL;
}
[/PHP]
now i figure the only tricky thing about this would be searching through the post data and selecting everytime it sees the world "uploaded".
A little help, ps...if i am missing a very obvious and common feature of php, please tell me as im still learning (for life).
thanks in advance.
But they wanted to be able to add more than one picture.
So, when the client clicks the "add another picture?" button, I used javascript to clone the initial input button, and then used a counter to increase a digit in the name. I.E:
First input buttons name => name="uploaded1 "
When Client Wants Another pick => name="uploaded2 "
...Another One => name="uploaded3 "
(and so on)
now on my php side, im using this to move the file into a folder on the server and save the path in a MySQL table.
[PHP]
$target = "wherepixgo/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$pictureurl = $target;
if(move_uploade d_file($_FILES['uploaded']['tmp_name'], $target))
{
if($target=="wh erepixgo/"){
$target="";
echo '<center><br /><br /><br />';
echo "No file Uploaded.";
echo '</center>';
echo '<br><br><br>' ;
}
else {
echo '<center>';
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
echo '<br><br><br></center>';
}
}[/PHP]
That's great for when I only had one picture to upload, and it would just look for one input file button name "uploaded". Now there are going to be input files to the Nth degree. How can I tell php to look at all of the posted variables named "uploaded(# )" and loop through an inputting code til no more.
Psuedocode:
[PHP]
while(there are posted variables with the name "uploaded#" ){
find it's # at the end of its name;
upload the current photo;
copy the path name into a variable so i can save it in MySQL;
}
[/PHP]
now i figure the only tricky thing about this would be searching through the post data and selecting everytime it sees the world "uploaded".
A little help, ps...if i am missing a very obvious and common feature of php, please tell me as im still learning (for life).
thanks in advance.
Comment