note 91368 added to function.imagejpeg

From: Date: Mon, 08 Jun 2009 20:31:49 +0000
Subject: note 91368 added to function.imagejpeg
Groups: php.notes 
Request: Send a blank email to php-notes+get-156487@lists.php.net to get a copy of this message
I had a problem with denied permissions when trying to upload AND resize an image having safe_mode on. This caused that I couldn't create the new file in which I wanted to resampled the image with nor with imagejpeg() nor with touch() and imagejpeg() after it. Here is my solution, I didn't test, but it's possible, it is biting some memory: <?php function resize($image, $target_file) { // $image is the uploaded image list($width, $height) = getimagesize($image['tmp_name']); //setup the new size of the image $ratio = $width/$height; $new_height = 500; $new_width = $new_height * $ratio; //move the file in the new location move_uploaded_file($image['tmp_name'], $target_file); // resample the image $new_image = imagecreatetruecolor($new_width, $new_height); $old_image = imagecreatefromjpeg($target_file); imagecopyresampled($new_image,$old_image,0,0,0,0,$new_width, $new_height, $width, $height); //output imagejpeg($new_image, $target_file, 100); } ?> As you can see, the function moves the uploaded file where you want to save the resampled image (move_uploaded_file is not restricted by safe_mode) and then you can resample the image, because it was created by moving it already. Note: the directory where you want to save the file must have permissions set to 0777. ---- Server IP: 69.147.83.197 Probable Submitter: 84.179.196.145 ---- Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php Edit -- https://master.php.net/note/edit/91368 Del: integrated -- https://master.php.net/note/delete/91368/integrated Del: useless -- https://master.php.net/note/delete/91368/useless Del: bad code -- https://master.php.net/note/delete/91368/bad+code Del: spam -- https://master.php.net/note/delete/91368/spam Del: non-english -- https://master.php.net/note/delete/91368/non-english Del: in docs -- https://master.php.net/note/delete/91368/in+docs Del: other reasons-- https://master.php.net/note/delete/91368 Reject -- https://master.php.net/note/reject/91368 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156487) next »