2013-03-16 67 views
0

imagecreatefromjpeg()函数说文件不存在,但是当我检查使用file_exists()函数,它说存在。imagecreatefromjpeg()函数没有歌厅文件

PHP代码是这样,

$path = "/home/content/html/uploads/test.jpg"; 

    if(file_exists($path)) { 
     echo "Exists!"; 
    } else { 
     echo "File Not Exists!"; 
    }  

    $resize = new Resize($path, $img['name']); 
    $resize->resizeImage($size[0], $size[1]); 
    $resize->preview(); 

而且我得到的输出喜欢,

Exists! 
Warning: imagecreatefromjpeg(/home/content/html/uploads/test.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/content/html/includes/resize.php on line 20 

目录结构,

  • /HTML
    • /上传
      • test.jpg放在
    • 的index.php
+1

什么是你的目录结构?是'html /'你的web根目录? – BenM 2013-03-16 12:37:33

+0

@BenM,是的HTML /是我的webroot。 – user1995997 2013-03-16 12:38:09

+0

检查文件权限 – 2013-03-16 12:38:36

回答

0

OK,我得到了解决。但首先我要感谢所有帮助我的人。

这是非常奇怪的问题。在服务器中,imagecreatefromjpeg()仅在存在没有“空间”的文件路径时才起作用。

如果我使用rawurlencode()转换成空间20%,那么问题仍然存在,所以我必须做的是,空格转换成别的东西使用文件上传过程中str_replace()函数的功能。

str_replace(" ", "_", $filename); 

在本地主机上,我使用“test.jpg放在”文件,但在服务器上也有与在那里的名字空间许多不同势文件,所以我在qustion使用“test.jpg放在”。 (对不起,那个)