PHP-GD imagejpeg unable to open

倖福魔咒の 提交于 2019-12-08 01:35:49

问题


When trying to save a thumbnail made with GD

imagejpeg($tnImage, "../../img/thumbs/".$maxWidth."x".$maxHeight."_".$filename);

I am getting the following error:

Warning: imagejpeg() [function.imagejpeg]: Unable to open '../../img/thumbs/80x80_55865-drops.jpg' for writing: No such file or directory in /home/user/workspace/stewart/server-side/libImg.php

/home/user/workspace/img/thumbs has its permissions set to 0x777.

What can be wrong here?


回答1:


Where are you running the file from? If it's from the server-side directory then I think you're missing a "../"

Try this:

var_dump(realpath("../../img/thumbs/".$maxWidth."x".$maxHeight."_".$filename));



回答2:


In

/home/user/workspace/stewart/server-side/

the directory

../../img/thumbs/  

would equate to

 /home/user/workspace/img/thumbs/

so you need

../../../img/thumbs/



回答3:


A workaround for this is providing the imagejpeg with the full path to the file.

So you can have in config.php something like

define('APPLICATION_PATH',  dirname(__FILE__));

Then in your functions.php call imagejpeg like this:

@imagejpeg($image, APPLICATION_PATH . '/uploads/myfile.jpg', $quality); 


来源:https://stackoverflow.com/questions/757008/php-gd-imagejpeg-unable-to-open

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!