Page 1 of 1

GD2 issue with using imagejpeg() function

Posted: Sat Jun 16, 2007 1:42 pm
by cralston
Hi, I run a couple of sites that are currently hosted on a server that uses php5, in safe mode.
my problem has to do with an image upload script that i wrote.
I'll describe it, show the method that is throwing the error, and then also post the error message that I'm getting.

Also, this code works flawlessly on my development environment (ubuntu 7.04, php5(no safe mode), Apache 2.2)


I have no problem getting my script to upload images. it saves them fine in the '/images/managed/' folder.
It is only when this method executes that I get the error

Code: Select all

private function createThumb($fName,$kind){
				$path =	$_SERVER['DOCUMENT_ROOT'].$this->imgPath;
				switch ($kind){
					case 'jpg' : $fullImg = imagecreatefromjpeg($path.$fName);break;
					case 'gif' : $fullImg = imagecreatefromgif($path.$fName);break;
					case 'png' : $fullImg = imagecreatefrompng($path.$fName);break;
				}
				//generate thumbnail ratio & size
					$size = getimagesize($path.$fName);
				//ratio
					($size[0]/$this->maxW) >= ($size[1]/$this->maxH) ? 
						$ratio = ($this->maxW/$size[0]) : ($ratio = $this->maxH/$size[1]);
				//create new thumbnail sized image
					$thumb = imagecreatetruecolor($size[0]*$ratio,$size[1]*$ratio);
				//copy full sized image to thumbnail size
					imagecopyresampled($thumb,$fullImg,0,0,0,0,$size[0]*$ratio,$size[1]*$ratio,$size[0],$size[1]);
				//save the copy (currently this goes to a folder called thumbs inside of $path)
					echo($path.$fName);
				switch ($kind){
//***************			case 'jpg' :  imagejpeg($thumb,$path.'thumbs.'.$fName);break;  ****************(this is the one)
					case 'gif' : imagegif($thumb,$path.$fName);break;
					case 'png' : imagepng($thumb,$path.$fName);break;
				}
	}
So, see the line marked (this is the one), well that's were the error is coming from so the rest of the GD code is fine i guess.

here is the error code:
Warning: imagejpeg() [function.imagejpeg]: Unable to access /sites/yuma4/deborahralston/home/public_html/images/managed/thumb_dfasf.jpg in /sites/yuma4/deborahralston/home/public_html/includes/imageMgr.php on line 346

Warning: imagejpeg() [function.imagejpeg]: Invalid filename '/sites/yuma4/deborahralston/home/public_html/images/managed/thumb_dfasf.jpg' in /sites/yuma4/deborahralston/home/public_html/includes/imageMgr.php on line 346

Posted: Sat Jun 16, 2007 3:01 pm
by cralston
Hi again,
I fixed this problem with a little research.
what worked for me was to touch($filename)
and then imagejpeg($filename);