Re: Image Creation and Saving

From: Date: Sun, 30 Jan 2005 08:52:06 +0000
Subject: Re: Image Creation and Saving
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-207707@lists.php.net to get a copy of this message
Are you making sure the $_SESSION['user_sn'] folder exists before saving the image into it? I'm asking because I originally thought it was a permission problem but php will tell you 'permission denied' if that was the case. At 05:05 PM 1/29/2005, NathanielGuy#21 wrote:
Hello everyone, I have been troubleshooting a problem with one of my scripts for a while now, its purpose is to allow a user to upload a file, save it to the server, resize it into a thumbnail, and save the thumbnail as well. In my script all goes well until it comes to saving the images, the script throws these errors: Warning: imagepng(): Unable to open '/home/blacknut/public_html/picserv/picserv_mysql/pictures/blacknute/15.png' for writing in /home/blacknut/public_html/picserv_mysql/addpic.php on line 91 Warning: imagepng(): Unable to open '/home/blacknut/public_html/picserv/picserv_mysql/pictures/blacknute/15t.png' for writing in /home/blacknut/public_html/picserv_mysql/addpic.php on line 95 Picture "ffq" was added to our database! The following is what we have generated and it is what others will see Here is the important part of the script, if more is needed i can post it as well.
        if ($mime_type == 'jpeg') {
        $new_image = imagecreatefromjpeg($_FILES['new_image']['tmp_name']);
//Create an image refrence
        }
        elseif ($mime_type == 'png') {
        $new_image = imagecreatefrompng($_FILES['new_image']['tmp_name']);
//Create an image refrence
        }
        elseif ($mime_type == 'gif') {
        $new_image = imagecreatefromgif($_FILES['new_image']['tmp_name']);
//Create an image refrence
        }
//Image Sizes
        list($new_image_width, $new_image_height) =
getimagesize($_FILES['new_image']['tmp_name']);//Get img size
        if ($new_image_width > $new_image_height) {//Get thumb size
        $percent_image_size = (200 / $new_image_width);
        }
        elseif ($new_image_width < $new_image_height) {
        $percent_image_size = (200 / $new_image_height);
        }
        else {
        $percent_image_size = (200 / $new_image_height);
        }
        $new_thumb_width = ($percent_image_size * $new_image_width);
        $new_thumb_height = ($percent_image_size * $new_image_height);
        $new_thumb_file = imagecreatetruecolor($new_image_width, $new_image_height);
imagepng($new_image, '/home/blacknut/public_html/picserv/picserv_mysql/pictures/' . strtolower($_SESSION['user_sn']) . '/' . $new_pic_filename . '.png'); //Copy pic to user dir as pic_id.png
        $new_thumb_image = imagecreatetruecolor($new_thumb_width,
$new_thumb_height); // Create Thumb file
        imagecopyresampled($new_thumb_image, $new_image, 0, 0, 0, 0,
$new_thumb_width, $new_thumb_height, $new_image_width, $new_image_height); //Copy resized to new thumb file
        imagepng($new_thumb_image,
'/home/blacknut/public_html/picserv/picserv_mysql/pictures/' . strtolower($_SESSION['user_sn']) . '/' . $new_pic_filename . 't.png'); //Save image thumb I am very new to file/image manipulation in php so if you see any errors, or unnecessary code please tell me. I'm not quit sure how everything works, although I do have a theoretical picture of how it does. Any comments will be appreciated. --nathan -- http://www.blacknute.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#207707) next »