2013-03-16 73 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放在」。 (對不起,那個)