Problem uploading picture to server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Bandy
Forum Newbie
Posts: 22
Joined: Sat Oct 21, 2006 5:14 am
Location: Croatia

Problem uploading picture to server

Post by Bandy »

Hi

I've wrote php code to upload file to server.
I used tutorial from this forum wrote by onion2k. Localy on apache web server works like charm but
when i uploaded it to server i get this
Warning: imagejpeg() [function.imagejpeg]: Unable to open '../images/thumb.jpg' for writing in /home/..etc
8O

What this mean??

Thanks
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

That your host doesn't have GD installed I guess :P
User avatar
Bandy
Forum Newbie
Posts: 22
Joined: Sat Oct 21, 2006 5:14 am
Location: Croatia

Post by Bandy »

What to do then? can something be done? Can i upload GD library by myself?
:oops:
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

The best thing you can do is to ask it from your host I guess.
What tutorial are you talking about by the way? Why do you need the imagejpeg() function in order to upload files?
User avatar
Bandy
Forum Newbie
Posts: 22
Joined: Sat Oct 21, 2006 5:14 am
Location: Croatia

Post by Bandy »

In tutorial section is post Uploading and resizing a image,
i guess imagejpg() function is for saving from temp location to server final destination.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

GD is installed. imagejpeg() was unable to open the file you specified to write the information out.
User avatar
Bandy
Forum Newbie
Posts: 22
Joined: Sat Oct 21, 2006 5:14 am
Location: Croatia

Post by Bandy »

how can i fix that?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Yeah, feyd is right. As always, I read too fast :P
Anyways, chmod() may be of interest, although I'm not sure it will help.
Please give us more details.
User avatar
Bandy
Forum Newbie
Posts: 22
Joined: Sat Oct 21, 2006 5:14 am
Location: Croatia

Post by Bandy »

Code: Select all

// Get the details of "imagefile"
$filename = $_FILES['imagefile']['name'];
$temporary_name = $_FILES['imagefile']['tmp_name'];
$mimetype = $_FILES['imagefile']['type'];
$filesize = $_FILES['imagefile']['size'];

//Open the image using the imagecreatefrom..() command based on the MIME type.
switch($mimetype) {
    case "image/jpg":
    case "image/jpeg":
        $i = imagecreatefromjpeg($temporary_name);
        break;
    case "image/gif":
        $i = imagecreatefromgif($temporary_name);
        break;
    case "image/png":
        $i = imagecreatefrompng($temporary_name);
        break;
}

//Delete the uploaded file
unlink($temporary_name);

$filename_a = "../images/".md5($filename).".jpg";

//Save a copy of the original
imagejpeg($i, $filename_a ,80);

//Specify the size of the thumbnail
$dest_x = 120;
$dest_y = 120;

//Is the original bigger than the thumbnail dimensions?
if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
    //Is the width of the original bigger than the height?
    if (imagesx($i) >= imagesy($i)) {
        $thumb_x = $dest_x;
        $thumb_y = imagesy($i)*($dest_x/imagesx($i));
    } else {
        $thumb_x = imagesx($i)*($dest_y/imagesy($i));
        $thumb_y = $dest_y;
    }
} else {
    //Using the original dimensions
    $thumb_x = imagesx($i);
    $thumb_y = imagesy($i);
}

//Generate a new image at the size of the thumbnail
$thumb = imagecreatetruecolor($thumb_x,$thumb_y);

//Copy the original image data to it using resampling
imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));

$filename_b = "../images/thum/".md5($filename).".jpg";

//Save the thumbnail
imagejpeg($thumb, $filename_b, 80); 
	
	$filename_a = "images/".md5($filename).".jpg";
	$filename_b = "images/thum/".md5($filename).".jpg";
Here is part of code for uploading file(picture) this code is from tutorial by onion2k.
I used ../ at first because administration pass access is set with .htacess file(directory pass protection), administrator can update picture.
Later i changed $filename_a and $filename_b for database.
Post Reply