2015-08-30 108 views
0

我正在開發一個包含文件上傳功能的網站。這在localhost上工作完美,但是一旦我將該網站上傳到我的服務器,它就會失敗。PHP的文件上傳在服務器上失敗

我有以下的代碼來處理文件上傳:

case "upload_to_gallery": 

     /******************************* 
     **** UPLOAD TO GALLERY **** 
     *******************************/ 

     if ($con->checkLogin() && isset($_FILES['uploaded_files'])) { 
      $gallery_name = $_POST['gallery_name']; 

      for ($i = 0; $i < count($_FILES['uploaded_files']['name']); $i++) { 
       list($width, $height, $type, $attr) = getimagesize($_FILES["uploaded_files"]['tmp_name'][$i]); 

       if ($_FILES['uploaded_files']['type'][$i] == "image/png" 
        || $_FILES['uploaded_files']['type'][$i] == "image/jpeg" 
        || $_FILES['uploaded_files']['type'][$i] == "image/gif" 
       ) { 
        $imgPath = "../files/img/galleries/" . $gallery_name . "/" . $_FILES['uploaded_files']['name'][$i]; 
        $thumbPath = "../files/img/galleries/" . $gallery_name . "/thumbs/" . $_FILES['uploaded_files']['name'][$i]; 

        move_uploaded_file($_FILES['uploaded_files']['tmp_name'][$i], strtolower($imgPath)); 

        $filehandler->makeThumbnails($imgPath, $thumbPath, 300, 215); 
       } 

      } 
      header('location: '.MAINPATH.'/galleri/'.$gallery_name.'?billeder_uploadet'); 

,我得到的錯誤,要上傳的服務器上的一些文件(影像)時是:

Warning: move_uploaded_file(../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phptu17Hf' to '../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg' in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35

Warning: getimagesize(../files/img/galleries/Test/1383204_10200900060289437_410542691_n.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 158

Warning: Division by zero in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 159

Warning: Division by zero in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 159

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 162

當我嘗試上傳0個文件到服務器,它給了我這個錯誤:

Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 26

我不瘦K是有道理的,因爲我正在檢查是否有任何文件已通過發送..

我認爲這可能與服務器上的權限有關,但所有相關的文件夾設置爲'755'。

我希望有人可能知道問題可能是什麼。 任何幫助將不勝感激。

+0

如果你的路徑(在3個第一個警告中)有'test'和'Test'。挑一個並堅持下去。 Linux對路徑和文件夾/文件名稱區分大小寫。 Windows不是。 – D4V1D

+0

僅僅因爲'$ _FILES ['uploaded_files']'存在,並不意味着沒有任何錯誤。檢查錯誤。 –

+0

謝謝@ D4V1D!就是這樣。如果您發佈答案,我會接受它。還有@Charlotte Dunois,也謝謝。我會嘗試檢查錯誤。我剛剛讀到它可以像我在我的問題中那樣完成,但顯然情況並非如此:) – Langkiller

回答

1

請仔細檢查您的錯誤。

Warning: move_uploaded_file(../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phptu17Hf' to '../files/img/galleries/test/1383204_10200900060289437_410542691_n.jpg' in /var/www/xn--cstanlg-rxa.dk/public_html/web/templates/formReceiverPost.php on line 35

Warning: getimagesize(../files/img/galleries/Test/1383204_10200900060289437_410542691_n.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /var/www/xn--cstanlg-rxa.dk/public_html/lib/class/FileHandler.php on line 158

你在你的路徑都testTest

請記住,Linux對文件和文件夾名稱區分大小寫。 Windows不是。這可以解釋爲什麼它在你的開發環境中工作,爲什麼它不再在你的prod服務器上運行。

所以選擇其中一個並堅持下去(我不建議在你的路徑中使用大寫字母)。