!RESOLVED! imagejpeg() :: checked everything still errors :(

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
blakewilliams
Forum Newbie
Posts: 4
Joined: Fri Mar 25, 2011 1:47 am

!RESOLVED! imagejpeg() :: checked everything still errors :(

Post by blakewilliams »

First post here... :D
First off, advanced thanks to anyone who spends time on this.

Here's the deal:

I'm trying to create a thumbnail of an uploaded user photo. I continue to get the following error:
Warning: imagejpeg() [function.imagejpeg]: Unable to open '/home/v5w3defp/public_html/sprahl.com/private/avatars/' for writing: Is a directory in /home/v5w3defp/public_html/sprahl.com/private/includes/functions.php
After scouring the nets, I've cleared up the possibility of it being a permissions issue (set to 777 for the sake of solving this problem), a safe_mode issue (set to 'off'), or an issue with the path (I think... I'm using $_SERVER['DOCUMENT_ROOT']).

Here are the relevant functions:

Code: Select all

function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
	$newImageWidth = ceil($width * $scale);
	$newImageHeight = ceil($height * $scale);
	$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
	$source = imagecreatefromjpeg($image);
	imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
	imagejpeg($newImage,$thumb_image_name,100);
}
function changePhoto($name){
	$upload_path = $_SERVER['DOCUMENT_ROOT'] . "/private/avatars/"; 
	$large_image_name = $name; 	// New name of the large image
	$thumb_width = "100";	// Width of thumbnail image
	$thumb_height = "100";

	$thumb_image_location = $upload_path.$thumb_image_name;
	$newname = $_SERVER['DOCUMENT_ROOT'] . '/private/user_photos/' . $large_image_name;

	$width = getWidth($newname);
	$height = getHeight($newname);
		
	// Prepare to chop off excess
	if($height > $width){
		$y1 = ($height - $width)/2;
		$x1 = 0;
		$w = $width;
		$h = $width;
	}
	if($width > $height){
		$x1 = ($width - $height)/2;
		$y1 = 0;
		$w = $height;
		$h = $height;
	}
		
	$scale = $thumb_width/$w;	
	$cropped = resizeThumbnailImage($thumb_image_location,$newname,$w,$h,$x1,$y1,$scale);			
}
Any help would be greatly appreciated.

Thanks.
Last edited by blakewilliams on Fri Mar 25, 2011 2:50 pm, edited 1 time in total.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: imagejpeg() :: checked everything still errors :(

Post by Darhazer »

check the values of $thumb_image_location and $newname
You are using $thumb_image_name; to build location, but this variable is not defined, $name ia assigned to $large_image_name instead.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: imagejpeg() :: checked everything still errors :(

Post by pickle »

Like the error says, you're trying to open a directory with imagejpeg() when you should be trying to open a file.

It looks like $image_thumb_name is not being built properly & therefore doesn't have the filename in it - just the path.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
blakewilliams
Forum Newbie
Posts: 4
Joined: Fri Mar 25, 2011 1:47 am

Re: imagejpeg() :: checked everything still errors :(

Post by blakewilliams »

Thanks to both of you guys for spotting what a long day of coding refused to allow me to. Nothing like a fresh set of eyes to point out the obvious. :)

Cheers.
Post Reply