I need to upload a preview image - smaller image to a different folder then my main image (larger image).
Is it possible using one form to upload 2 files to 2 separate folders?
This is the form code I have been trying to get to work:
<form action="add_product_script.php" method="post" enctype="multipart/form-data">
<table>
<tr style="vertical-align: top;">
<td width="400px">
Upload large product image:<br />
<input type="file" name="upload[]" /><br />
Upload small product image (preview):<br />
<input type="file" name="upload[]" /><br />
...
Product description:<br />
<input type="submit" value="Upload" /><br />
</form>
And this is the PHP script I am using:
$success = 0;
$fail = 0;
$uploaddir = 'uploads/';
for ($i=0;$i<4;$i++)
{
if($_FILES['userfile']['name'][$i])
{
$uploadfile = $uploaddir . basename($_FILES['userfile']['name'][$i]);
$ext = strtolower(substr($uploadfile,strlen($uploadfile)-3,3));
if (preg_match("/(jpg|gif|png|bmp)/",$ext))
{
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile))
{
$success++;
}
else
{
echo "Error Uploading the file. Retry after sometime.\n";
$fail++;
}
}
else
{
$fail++;
}
}
}
echo "<br> Number of files Uploaded:".$success;
echo "<br> Number of files Failed:".$fail;
Last above code was ripped off the internet for multiple images - only goes to one folder though - maybe do this without a loop?
Any ideas please.
Cheers