Jump to content

imagejpeg: problem saving to file


alhena

Recommended Posts

Hi all,

 

I have a script that creates an image and saves it to a file. Until recently, I had PHP 5.2.11 on the server, yesterday it got upgraded to 5.3.3 ("-7+squeeze1" to be exact, no idea what that means). Ever since, the images refuse to be saved. I can create the image just fine, even display in the browser (when header is set to image). I'm not getting any error messages, which may or may not have to do with the error reporting settings in the server configuration (I don't have access to that or the error logs). error_reporting ( E_ALL ) doesn't make a difference.

 

// this is not working
imagejpeg($image, "testing.jpg");

// this is working fine
imagejpeg($image);

 

I'm wondering if this has to do with safe_mode being enabled in the new PHP version. To be precise, it says "on" for Local Value and "off" for Master Value. They were both set to "off" in the old configuration. I did make sure to chmod the directory where the image is supposed to be saved to to 777, but it made no difference.

 

Do I need to email the tech guys to turn safe_mode off? Or is the problem somewhere else?

Link to comment
Share on other sites

Which one do you mean? There are several that mention problems with safe_mode. I tried both "touch" and "ini_set", and neither works. The third mentions something about moving an uploaded file, which is not what I have.

 

Is there any other way to get around safe_mode, or is it simply impossible to save an image to file in safe_mode?

Link to comment
Share on other sites

You need to first find out why the function is failing. Use both of the following lines to set the error_reporting/display_errors settings (assuming your host has not disabled ini_set or the error_reporting statements) -

 

ini_set("display_errors", "1");
error_reporting(-1);

Link to comment
Share on other sites

Thanks. This is interesting... error_reporting ( E_ALL ) did not show any errors, but this made them show up.

 

Warning: imagejpeg(): SAFE MODE Restriction in effect. The script whose uid is 10000 is not allowed to access [directory link] owned by uid 33 in [script link] on line 40 Warning: imagejpeg(): Invalid filename in [script link] on line 40

 

So safe mode really is to blame, it seems. The directory mentioned in the warning does have 777 rights, so it's a bit odd why it would still be restricted.

Link to comment
Share on other sites

This feature has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

 

^^^ Given that safe mode is depreciated and soon to be removed from php, I'm wondering why your host has turned it on, assuming they know that they have turned it on.

 

Safe mode doesn't check the file/folder permission settings, it checks the user id of the file/folder owner and that of the currently running script.

Link to comment
Share on other sites

I'm wondering the same, especially since safe mode was off in the old PHP installation. Maybe it was an oversight, or it's set to on by default and has to be adjusted manually.

 

Is there any way I can change the user id of the folder and the script so they match? Or is this out of my hands?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.