Uploading several pictures with loop
Posted: Thu Jun 30, 2005 3:44 am
From a form like this one, I'm trying to upload and thumbnail 3 pictures in 1 shot. The form is more or less like follows but the things do not work:
And the PHP is this way:
Code: Select all
<input name="e;userfileї]"e; type="e;file"e; /><br />
<input name="e;userfileї]"e; type="e;file"e; /><br />
<input name="e;userfileї]"e; type="e;file"e; /><br />Code: Select all
$totalimages=count($userfile);
if($totalimages!=0){
for($a=0;$a<$totalimages;$a++){
$msg = "";
switch(!strcasecmp($_SERVER['REQUEST_METHOD'], "POST")) {
case true:
$tmp = getcwd()."/".$_FILES['userfile[$a]']['name'];
if(!@move_uploaded_file($_FILES['image[$a]']['tmp_name'], $tmp)) {
$msg = "";
break;
}
$fp = fopen($tmp, "rb");
$str = fread($fp, filesize($tmp));
fclose($fp);
unlink($tmp);
$im1 = ImageCreateFromString($str);
$imgname = $ref."_thumb_".$a;
$maxwidth =250;
$maxheight = 200;
$width1 = ImageSX($im1);
$height1 = ImageSY($im1);
$width2 = $maxwidth;
$height2 = floor(($width2 * $height1) / $width1);
if($maxheight > 0 && $height2 > $maxheight) {
$height2 = $maxheight;
$width2 = floor(($height2 * $width1) / $height1);
}
$im2 = ImageCreateTrueColor($width2, $height2);
ImageCopyResampled($im2, $im1, 0, 0, 0, 0, $width2, $height2, $width1, $height1);
ImageJpeg($im2, "thumb/".$imgname.".jpg");
$msg = "Ok";
$im3 = ImageCreateFromString($str);
$imgname2 = $ref."_full_".$a;
$maxwidth2 = 500;
$maxheight2 = 300;
$width12 = ImageSX($im3);
$height12 = ImageSY($im3);
$width22 = $maxwidth2;
$height22 = floor(($width22 * $height12) / $width12);
if($maxheight2 > 0 && $height22 > $maxheight2) {
$height22 = $maxheight2;
$width22 = floor(($height22 * $width12) / $height12);
}
$im4 = ImageCreateTrueColor($width22, $height22);
ImageCopyResampled($im4, $im3, 0, 0, 0, 0, $width22, $height22, $width12, $height12);
ImageJpeg($im4, "full/".$imgname2.".jpg");
ImageDestroy($im1);
ImageDestroy($im2);
ImageDestroy($im3);
ImageDestroy($im4);
break;
}}