Forum Moderators: coopster
I am basically trying to reduce the image stored in $_FILES['picture']['tmp_name'] and then send it to my destination dir.. but i get this error..
TIA for any help.
the image is a 300k jpeg...the script will take smaller fine and resize one for a thumbnail, but if the image is bigger like 300k it gives that error..
i have read various posts about this to no avail, but unless when i resize the image it uncompresses it i dont understand how it burns 8m like that...
//check for jpeg
if ($imagetype!= 'image/pjpeg') {
echo 'Only jpegs are accepted, please use your back button and retry';
exit;
}
//check size
if ($imagesize > 1000000) {
echo 'File size exceeds limit, please use your back button and retry';
exit;
}
else {
$filename = "".uniqid(I).".jpg";
$upfiledir = 'uploads/' .$filename;
$thumb = "thumbs/$filename";
move_uploaded_file($imagetemp, $upfiledir);
}
if (isset($HTTP_POST_VARS['model']) && $HTTP_POST_VARS['model']!='')
$sql = "insert into cars
(model, description, price, year, picture, thumb)
values
('$model', '$description', '$price', '$year', '$upfiledir','$thumb')";
$result = mysql_query($sql, $conn);
if (!$result) {
print "There was a database error when executing <pre>$sql</pre>";
print mysql_error();
exit;
}
/*
if (move_uploaded_file($imagetemp, $upfiledir)) {
$msg = "File is successfully uploaded.";
}
else {
$msg = "File is not successfully uploaded.";
//print_r($_FILES);
} */
// show what was uploaded
print ("$msg<br />\n");
print ( "This is the picture file, $filename, you have uploaded:<br />");
print ( "<img src=\"$upfiledir\" border=\"0\"><br /><br />");
// create thumbnail image
$sourcefile = "$upfiledir";
if (!$max_width)
$max_width = 80;
if (!$max_height)
$max_height = 60;
$targetfile = "$thumb";
$jpegqual = 75;
/* Get the dimensions of the source picture */
$size=getimagesize("$sourcefile");
$width = $size[0];
$height = $size[1];
$source_id = imageCreatefromjpeg("$sourcefile");
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
/* Create a new image object (not neccessarily true colour) */
$target_id=imagecreatetruecolor($tn_width,$tn_height);
$target_pic=imagecopyresampled
($target_id,$source_id,0,0,0,0,$tn_width,$tn_height,$width,$height);
imagejpeg ($target_id,"$targetfile",$jpegqual);
//display thumbnail
print ( "This is the thumbnail file:<br />");
print ( "<img src=\"$thumb\" border=\"0\">");
This is my script..only been doing php a few weeks now so any tips are soooo welcome..
Thanks
[devnetwork.net...]
and
www.fuitadnet.com/forums/showthread.php?s=&threadid=782
There's more to be found if you enter "imagecreatefromjpeg Allowed memory size" in Google.
[edited by: jatar_k at 8:25 pm (utc) on Nov. 24, 2003]
[edit reason] delinked [/edit]