multiple image upload + resizing
Posted: Tue Apr 25, 2006 8:20 pm
I have written a script to handle mutiple image uploads coupled with image resizing. The number of images that can be uploaded at this time is 4. Tha code is below
The problem I am facing is it uploads the 1st, 3rd and 4th images perfectly. It copies the 1st image over as the 2nd so basically the 1st and the 2nd are the same images and it gives me this error mssg
Any help will be appreciated. Thanks
Code: Select all
$numoffile = 4;
$file_dir = "images/";
if ($_POST) {
for ($j=0;$j<$numoffile;$j++) {
if (trim($_FILES['imagefile']['name'][$j])!="") {
$filename = $_FILES['imagefile']['name'][$j];
$temporary_name = $_FILES['imagefile']['tmp_name'][$j];
$mimetype = $_FILES['imagefile']['type'][$j];
$filesize = $_FILES['imagefile']['size'][$j];
$split = explode(".", $filename);
$name=$split[0];
if (($mimetype=="image/gif") || ($mimetype=="image/png")) {
echo " Error Mssg";
} else {
switch($mimetype) {
case "image/jpg":
case "image/jpeg":
case "image/pjpeg":
$i = imagecreatefromjpeg($temporary_name);
break;
}
unlink($temporary_name);
//Specify the size of the new product image
$dest_x = 300;
$dest_y = 300;
if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
if (imagesx($i) >= imagesy($i)) {
$thumb_x = $dest_x;
$thumb_y = imagesy($i)*($dest_x/imagesx($i));
} else {
$thumb_x = imagesx($i)*($dest_y/imagesy($i));
$thumb_y = $dest_y;
}
} else {
$thumb_x = imagesx($i);
$thumb_y = imagesy($i);
}
$thumb = imagecreatetruecolor($thumb_x,$thumb_y);
imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));
imagejpeg($thumb, "images/".$name.".jpg", 80);
chmod("images/".$name.".jpg", 0777);
echo " Image <?=$name?>.jpg has been uploaded";
}
}
}
}
if (isset($h)&&$h>0) print "Your file(s) has been uploaded.<br>";
print "<form method='post' enctype='multipart/form-data'>";
for($k=0;$k<$numoffile;$k++) {
print "<input type='file' name='imagefile[]' size='30'><br>";
}
print "<input type='submit' name='action' value='Upload'>";
print "</form>";Code: Select all
Warning: unlink(): No such file or directory in blah blah on line 35