1

Every time I try to write an image using imagejpeg(), I get the following error:

Warning: imagejpeg() [function.imagejpeg]: Unable to open '/home/userdir/public_html/files/images/thumbs/

I've checked and this dir has 777 permissions, so it should be able to write to it.

Stranger still, the destination file path being given to imagejpeg() is actually:

/home/userdir/public_html/files/images/thumbs/small/1113/XM324980.jpg

I've checked, and permissions are set to 777 all the way. The file doesn't already exist.

Why would it be having trouble opening the "thumbs" dir to write to the thumbs/small/1113/ dir?

5
  • 4
    Does the /small/1113/ directory exists? Commented Sep 5, 2012 at 16:34
  • 4
    Don't set permission to 777 ever. Cordially, your sysadmin. Commented Sep 5, 2012 at 16:36
  • Show some code, if you want accurate answers. Commented Sep 5, 2012 at 16:50
  • TBH you don't need to be able to write to it. The user the webserver is running under needs to be able to write to it. Not that that is your problem though. Commented Sep 5, 2012 at 17:03
  • @InternetSeriousBusiness Yeah, it was changed just to make sure that wasn't causing a problem. Changed it right back after debugging the code. Commented Sep 5, 2012 at 17:57

1 Answer 1

4

The imagejpeg() will only create the image in the destination directory but you have used another two sub-directories that is small/1113 for creating the directories you have to use the mkdir functionality. Please make sure you have created that first and then create the images inside it.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, I thought I was creating it! Turns out I made a dumb mistake, because the code that checked if the subdir exists was checking the source dir instead of the destination dir. Changed that and it works great now. Thanks! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.