Multipe Image Upload script help please
Posted: Thu Sep 03, 2009 4:21 pm
Hi Guys
I am having a little problem. I already have an image uploading script that works perfectly for just one image, however I need it to be able to upload 5. This is my uploading script.
My PHP Script
AND MY FORM
MY EFFORT AT A DOUBLE UPLOAD!
Now this works perfectly for just one image but as I said I need more than one, so I tried this code but it only uploads the first image
If anyone can see a problem with this then a little help would be great thanks, its really bugging me.. I thought it must work!
I am having a little problem. I already have an image uploading script that works perfectly for just one image, however I need it to be able to upload 5. This is my uploading script.
My PHP Script
Code: Select all
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
# escape data and set variables
$epn = time();
$EventPicture = 'picture1'.$epn;
$EventPicture2 = 'picture2'.$epn;
$EventPicture3 = 'picture3'.$epn;
$EventPicture4 = 'picture4'.$epn;
$EventPicture5 = 'picture5'.$epn;
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }
print "<strong>Thank you very much for signing up to our service.</strong><br><br> We have sent you a confirmation email. You will be redirected within 5 seconds. If you are not, please click <a href='mainpage.php'>here</a>.
</tr>
</p><br /><br /></div><div style='clear: both;'></div><div id='footer'></div></div><div style='clear: both;'></div></div></body></html>";
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
$newwidth=300;
$newheight=($height/$width)*300;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename = "images/".$EventPicture.".jpg";
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
exit;
}
Code: Select all
<form method="post" action="multimage.php" enctype="multipart/form-data">
<table>
<tr><td class="userloginbuyerl"><br><br><strong>PROPERTY PICTURES</strong><BR>Use this section to upload photographs of your property. You may upload 5 pictures. With the first, being your main picture.</td></tr>
<tr><td><input type="file" name="uploadfile"/></td></tr>
<tr><td></td><td><input type="submit"></td></tr>
</table>
Now this works perfectly for just one image but as I said I need more than one, so I tried this code but it only uploads the first image
Code: Select all
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
# escape data and set variables
$epn = time();
$EventPicture = 'picture1'.$epn;
$EventPicture2 = 'picture2'.$epn;
$EventPicture3 = 'picture3'.$epn;
$EventPicture4 = 'picture4'.$epn;
$EventPicture5 = 'picture5'.$epn;
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }
print "<strong>Thank you very much for signing up to our service.</strong><br><br> We have sent you a confirmation email. You will be redirected within 5 seconds. If you are not, please click <a href='mainpage.php'>here</a>.
</tr>
</p><br /><br /></div><div style='clear: both;'></div><div id='footer'></div></div><div style='clear: both;'></div></div></body></html>";
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
$newwidth=300;
$newheight=($height/$width)*300;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename = "images/".$EventPicture.".jpg";
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
$uploadedfile1 = $_FILES['uploadfile1']['tmp_name1'];
$src1 = imagecreatefromjpeg($uploadedfile1);
list($width1,$height1)=getimagesize($uploadedfile1);
$newwidth1=300;
$newheight1=($height1/$width1)*300;
$tmp1=imagecreatetruecolor1($newwidth1,$newheight1);
imagecopyresampled1($tmp1,$src1,0,0,0,0,$newwidth1,$newheight1,$width1,$height1);
$filename1 = "images/".$EventPicture2.".jpg";
imagejpeg($tmp1,$filename1,100);
imagedestroy($src1);
imagedestroy($tmp1);
exit;
}
?>
Code: Select all
<form method="post" action="multimage.php" enctype="multipart/form-data">
<table>
<tr><td class="userloginbuyerl"><br><br><strong>PROPERTY PICTURES</strong><BR>Use this section to upload photographs of your property. You may upload 5 pictures. With the first, being your main picture.</td></tr>
<tr><td><input type="file" name="uploadfile"/></td></tr>
<tr><td><input type="file" name="uploadfile1"/></td></tr>
<tr><td></td><td><input type="submit"></td></tr>
</table>
</form>