Jump to content


Photo

Problem with imagejpeg


  • Please log in to reply
2 replies to this topic

#1 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 25 September 2006 - 02:29 PM

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

<?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;
	}

?>


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


Tell me the problem, I will try tell you the solution

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 25 September 2006 - 02:53 PM

I also have the phps file uploaded

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

Please help
Tell me the problem, I will try tell you the solution

#3 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 25 September 2006 - 03:48 PM

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
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users