Jump to content

Archived

This topic is now archived and is closed to further replies.

onlyican

Problem with imagejpeg

Recommended Posts

Hey guys

Soz about the urgent, but it is

i have a small static class to upload and resize images
I am testing this live on the server

This script allows for jpg, gifs, and pngs

I can upload gifs and pngs
but
jpeg is having some trouble

The snippit refering to resize and saving is

[code]
<?php
function ResampleImage(){
//$this->username is the users username,
$this->file_ext is the file extension (jpg, gif, png)
$new_file_name = $this->username.".".$this->file_ext;

//$this->save_to is the directory
$dir = $_SERVER['DOCUMENT_ROOT']."/".$this->save_to.$new_file_name;


$image_p = imagecreatetruecolor($this->new_width, $this->new_height);


switch($this->file_ext){
case "jpg":
$image = imagecreatefromjpeg($_FILES["ufile"]["tmp_name"]);
break;

case "gif":
$image = imagecreatefromgif($_FILES["ufile"]["tmp_name"]);
break;

case "png":
$image = imagecreatefrompng($_FILES["ufile"]["tmp_name"]);
break;

}


imagecopyresampled($image_p, $image, 0,0,0,0,$this->new_width, $this->new_height, $this->width, $this->height);
$success_upload = false;

switch($this->file_ext){
case "jpg":

//This line is 147
if(imagejpeg($image_p, $dir)){
$success_upload = true;
}
break;

case "gif":
if(imagegif($image_p, $dir)){
$success_upload = true;
}
break;
case "png":
if(imagepng($image_p, $dir)){
$success_upload = true;
}
break;
}

imagedestroy($image_p);
if($success_upload){
$this->allowed_upload = 1;
}else{
$this->allowed_upload = 3;
}

?>

[/code]

The error is
Warning: imagejpeg(): Unable to open '/home/onlyican/public_html/disabledfriends/friends/jamie.jpg' for writing in /home/onlyican/public_html/disabledfriends/inc/class_upload_img.php on line 147


The chmod is 777
Gifs and Pngs are working no probs, as u can see, the only difference between the image types is the function name
looking at the error
Its going to the right folder
the username and file extension is there

Any ideas

Share this post


Link to post
Share on other sites
I also have the phps file uploaded

http://onlyican.com/class_upload_img.phps
If this helps

Please help

Share this post


Link to post
Share on other sites
Dont worry, I seemed to have solved the issue

A friend of mine tested the function using a different user
As this is a remake to the site
I had an image online called jamie.jpg
For some reason it didn't want to overwrite it
I renamed the already uploaded jamie.jpg to jamieX.jpg
then tried uploading and it worked
then I tried uploading again, testing the overwriting, to see if I need to do unlink
but it worked

so I am guessing that the oroiginal file was corrupt or something

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.