doubi2228 2010-05-19 22:26
浏览 41
已采纳

php GD图像无法创建的问题

With the following code, my browser is returning 'image not created or saved'. I assure you the location of the image exists. So the line within the if statement is returning false for some reason, and yes GD is installed. Any ideas?

if ($img = @imagecreatefromjpeg("/var/www/images/upload/1/1.jpg")) {

            die("image was created");

     } else {

         die ("image was not created or saved");

     }

OK, I did this:

<?php

error_reporting(E_ALL);

if (fopen('/var/www/images/upload/1/1.jpg')) {

    echo 'file was opened';

} else {

    echo 'file was not opened';

}


?>

It returns file was not opened every time, the apache group has all permissions for all of these folders. Is GD or PHP a different username?

After doing an is_readable() from a test script, it returned true. What else could the problem be?

So... when I run the script:

error_reporting(E_ALL);
imagecreatefromjpeg("/var/www/images/upload/1/1.jpg");
print_r(error_get_last());
echo ("hi");

I receive a white screen of death. If I comment out the imagecreatefromjpeg line, the screen displays 'hi'

Just tried this on a 500k jpg image to see if it's a memory issue, but still got the white screen.

When I run the imagecreatefromjpeg within an if statement and run the script through the terminal, the imagecreatefromjpeg is a success! =\ Still can't figure out why it wouldn't work otherwise. EDIT: Running this exact script through my browser also is a success.

  • 写回答

4条回答 默认 最新

  • doumalu9257 2010-05-19 22:41
    关注

    Clearly the value of $img is not evaluating to true.

    Sorry, that was just too much to resist.. my point was, that there is no need for all that other crap in your post.

    Image creation can fail if the process can't read the file. try fopen-ing the file for read. also, get rid of the error suppression in front of your function call (@) . Then set error_reporting to E_ALL and display_errors to on.

    Update: if the fopen is failing, then the user running php does not have read permissions for the file. Try using fopen and fwrite to write a file to /tmp to see which user your php/apache process is running as. Then make sure that user has read access. Or you can just try chmoding the file to o+r to confirm that read access for everyone fixes our problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 机器学习简单问题解决
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写