Saving an image with the imagejpeg() function
October 12, 2007 8:20 PM   RSS feed for this thread Subscribe

Is there any way around this php problem involving imagejpeg()?

I'm working on a form that uploads a file to a folder using PHP 5. When it uploads, I'm trying to create a resized version of the image using imagecopyresampled. Then I try to use imagejpeg() to save the resized image to a seperate folder.

It throws up this error...

Unable to open 'Y' for writing: Is a directory in Y

I've googled around, and CHMODed the folder to 777, but I still can't put an end to this error.

Is there some workaround I could try? If I can't save it to a folder, can I try to insert it into a table in MySQL?

In the worst case scenario, I can dynamically resize the images for the page I want to create, but that seems like it would put far too much strain on the server.

Here's the chunk of code I'm using
$thisimage = # information pulled from higher up in the file
$dir = "./images/smaller/"; #according to 2 different ftp programs, this directory should be writable
$quality = 60;
$image_location = "./images/";
$image_location .= $thisimage;
$src = ImageCreateFromJPEG("$image_location");
$width =ImageSx($src);
$height = ImageSy($src);
$x = $width/4;
$y = $height/4;
$dst = ImageCreateTrueColor($x,$y);
imagecopyresampled($dst,$src,0,0,0,0,$x,$y,$width,$height);

imagejpeg($dst,$dir , $quality);
posted by drezdn to computers & internet (2 comments total) 1 user marked this as a favorite
This problem had been bugging me all day, and then I found the answer just after posting... $dir should include a filename.
posted by drezdn at 8:24 PM on October 12, 2007


Sometimes writing it down is all it takes :)
posted by sanka at 8:37 PM on October 12, 2007


« Older My internet is acting weird (I...   |   I'm going to the Dallas Cowboy... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
Getting Google Images results via PHP? August 11, 2008
phpleh November 12, 2007
WordPress: How to resize and cache images on the fly? June 25, 2007
Light-weight image browser? May 26, 2006
PHP - resize image to a specific (k) size? January 12, 2006