Jump to content

Recommended Posts

I have a form to upload multiple images at once, that works good. It's when I put in the resize function that it won't work. for some reason, it only does it for 1 image. every other get's an error msg

 

here the script. can anybody something wrong with it?

function resize($img)
{
	$src = imagecreatefromjpeg($img);
	$width = imagesx($src);
	$height= imagesy($src);
	$x = 600;
	$y = ($height/$width) * 600;
	$dst = imagecreatetruecolor($x,$y);
	imagecopyresampled($dst,$src,0,0,0,0,$x,$y,$width,$height);
	$file = "upload/$img";
	imagejpeg($dst,$file);

	return $file;
}


foreach ( $_FILES["pictures"]["error"] as $key => $error ) 
	{
		if ( $error == UPLOAD_ERR_OK ) 
			{

				 $tmp_name = $_FILES["pictures"]["tmp_name"][$key];					
       				 $name = $_FILES["pictures"]["name"][$key];
				 $path = "upload/$name";



        			 if( is_uploaded_file($tmp_name))
				 	{
						list($width,$height) = getimagesize($tmp_name);
						$resize = resize($name);

						echo "<img src=\"".$resize."\"><br /><br />";

					}


		}
	}

Link to comment
https://forums.phpfreaks.com/topic/52972-resizing-multiple-images/
Share on other sites

These are the errors I'm getting...it's for every image I upload.If I upload 4 images, i'll get it 4 tmes

 

 

Warning: imagecreatefromjpeg(IMG_2646.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 80

 

Warning: imagesx(): supplied argument is not a valid Image resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 81

 

Warning: imagesy(): supplied argument is not a valid Image resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 82

 

Warning: Division by zero in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 84

 

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 85

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 86

 

Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 88

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.