Jump to content

[SOLVED] imagecreatefromjpeg() has filesize issues ?


Recommended Posts

Ok here is my upload script.

 

Basically it uploads the original file to upload/large a thumbnail file to upload/thumbs and an enlarge file to upload/enlarge...

 

the code ! - Sorry if formatting sux

if(isset($_POST['Submit']))

{
$size = 100; // the thumbnail height
$size2 = 500; // the enlarged height

$filedir = 'upload/large/'; // the directory for the original image
$enlargedir = 'upload/enlarge/'; // the directory for the enlarge image
$thumbdir = 'upload/thumbs/'; // the directory for the thumbnail image
$prefix = get_rand_id(5); // the prefix to be added to the original name

$maxfile = '8000000';
$mode = '0666';

$userfile_name = $_FILES['image']['name'];
$userfile_tmp = $_FILES['image']['tmp_name'];
$userfile_size = $_FILES['image']['size'];
$userfile_type = $_FILES['image']['type'];

if($userfile_size >= $maxfile)
	{
	?>
		<center><br /><br /><br />
		<font color="#FF0000">The picture file you are trying to upload exceeds the 10MB limit. Please decrease the filesize and try again. Thank You!.</font><BR />
		</center>
		<meta http-equiv=refresh content='5;url=javascript:history.go(-1)'>
	<?
		exit;
	}

//echo $userfile_size;

if (isset($_FILES['image']['name'])) 
{
	$prod_img = $filedir.$prefix.$userfile_name;
	$prod_img_enlarge = $enlargedir.$prefix.$userfile_name;
	$prod_img_thumb = $thumbdir.$prefix.$userfile_name;
	move_uploaded_file($userfile_tmp, $prod_img);
	chmod ($prod_img, octdec($mode));
	// START THUMBNAIL RESIZE -----------------------------------------------
	$sizes = getimagesize($prod_img);

	$aspect_ratio = $sizes[1]/$sizes[0]; 

	if ($sizes[1] <= $size)
		{
			$new_width = $sizes[0];
			$new_height = $sizes[1];
		}
	else
		{
			$new_height = $size;
			$new_width = abs($new_height/$aspect_ratio);
		}

	$destimg = imagecreatetruecolor($new_width,$new_height)or die('Problem In Creating image');

	$srcimg = imagecreatefromjpeg($prod_img)or die('Problem In opening Source Image');

	if(function_exists('imagecopyresampled'))
		{
			imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg))
			or die('Problem In resizing');
		}
	else
		{
			imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg))
			or die('Problem In resizing');
		}
	ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');

	imagedestroy($destimg);
	echo "<br>got here 1!"; // 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
	//START ENLARGE RESIZE --------------------------------------------------------
	$xsizes = getimagesize($prod_img);

	$xaspect_ratio = $xsizes[1]/$xsizes[0]; 

	if ($xsizes[1] <= $size2)
		{
			$xnew_width = $xsizes[0];
			$xnew_height = $xsizes[1];
		}
	else
		{
			$xnew_height = $size2;
			$xnew_width = abs($xnew_height/$xaspect_ratio);
		}
	echo "<br>got here 2a!"; // 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
	$xdestimg = imagecreatetruecolor($xnew_width,$xnew_height)or die('Problem In Creating image');
	echo "<br>got here 2b!"; // 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
	$xsrcimg = imagecreatefromjpeg($prod_img)or die('Problem In opening Source Image');
	echo "<br>got here 2c!"; // 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
	if(function_exists('imagecopyresampled'))
		{
			imagecopyresampled($xdestimg,$xsrcimg,0,0,0,0,$xnew_width,$xnew_height,ImageSX($xsrcimg),ImageSY($xsrcimg))
			or die('Problem In resizing');
		}
	else
		{
			imagecopyresized($xdestimg,$xsrcimg,0,0,0,0,$xnew_width,$xnew_height,ImageSX($xsrcimg),ImageSY($xsrcimg))
			or die('Problem In resizing');
		}
	ImageJPEG($xdestimg,$prod_img_enlarge,90) or die('Problem In saving');
	echo "<br>got here 2d!"; // 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
	imagedestroy($xdestimg);
	echo "<br>got here 2e!"; // 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
}

echo '
<a href="'.$prod_img.'">
	<img src="'.$prod_img_enlarge.'" width="'.$new_width.'" height="'.$new_height.'">
</a>';

$image = $prefix.$userfile_name;	

$iQuery = "INSERT INTO imgcon (fname, lname, company, address, state, city, zip, phone, email, imgfile, txt, timestamp, date)
		   VALUES ('$fname', '$lname', '$company', '$address', '$state', '$city', '$zip', '$phone', '$email', '$image', '$txt', CURRENT_TIMESTAMP(), now())";
$iSql = mysql_query($iQuery) or die('<br />Query Error : <br />' . mysql_error());


?>
        <meta http-equiv=refresh content='3;url=thankyou.php?xyz=<? echo $mergename; ?>'>
    <?

}

 

 

Now the issue is ... if u look at the // Start Enlarge Resize portion ....

the echoes work up to Got Here 2b... so my assumption is that imagecreatefromjpeg() is the issue here.

 

Everything works just fine as long as the image filesize is no bigger then 1MB.... when i try to upload larger filesizes like 3 + the // Start Enlarge Resize portion doesnt go through all the way and stops to a halt at that function.

 

Anybody know about this issue whatever it may be ?

 

Could it be because im using that function twice ? cause when i flip and do Enlarge first and Thumbnail second ..

the thumbnail doesnt get uploaded as opposed to the enlarge.

 

Thanks

~iPixel

Everything works just fine as long as the image filesize is no bigger then 1MB.... when i try to upload larger filesizes like 3 + the // Start Enlarge Resize portion doesnt go through all the way and stops to a halt at that function.

 

it sounds like you have isolated the problem to file size. perhaps a file upload size limitation is truncating your files so that they are not valid? but it seems to me they would upload completely or fail completely, not end up with a partial upload. also, you're using imagecreatefromjpeg(). is $prod_image always a jpeg?

 

From your link: Do you have error reporting turned on?

error_reporting  6135 whatever that means =X.

 

yeas $prod_img is always JPG.

 

i dunno if its a memory limit problem cause it fails on a 3.7MB file when my upload and post limit is at 8M

 

my memory_limit is at 64M and both post_max_size and upload_max_filesize are set to 8M.

 

Thanks for taking a look...

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.