The user can upload a jpeg for their avatar, but I want to keep it to a certain size, and I'm running into an error...
PHP Code:
$regexp = ereg_replace(" ", "", $_FILES['newPic']['name']); $max_width=200; $max_height=200; $src = $_FILES["newPic"]["tmp_name"]; list($width,$height) = getimagesize($_FILES["newPic"]["tmp_name"]); $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if( ($width <= $max_width) && ($height <= $max_height) ) { $tn_width = $width; $tn_height = $height; } elseif (($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; }
$tmp=imagecreatetruecolor($tn_width,$tn_height); $src3 = imagecreatefromjpeg($src); imagecopyresampled($tmp,$src3,0,0,0,0,$tn_width, $tn_height,$width,$height); //puts the file in the pictures directory move_uploaded_file($tmp, "files/Pictures/" . $regexp);
But when everything gets executed, it doesn't save the file to the destination address. Any ideas? Thanks.
edit: sometimes this error pops up
Code:
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/content/k/b/f/kbfirebreather/html/checkSettingsChanged.php on line 93
Last edited by kbfirebreather : 04-08-2008 at 01:59 PM.
Reason: got an error
|