2012-02-24 46 views
0

這裏是我用來上傳文件並將其解壓縮到目錄中的代碼。 但問題是,對於大於5MB的文件,它似乎很慢。 我認爲它不必與網絡,因爲它在本地計算機。 我是否需要編輯php.ini文件或apache或任何其他workarround中的任何參數?在PHP中緩慢上傳joomla controler

$target_path = "../somepath/"; 
      $target_path .= JRequest::getVar('uploadedDirectory')."/"; 

      $target_Main_path= JRequest::getVar('uploadedDirectory')."/"; 

      $folderName = $_FILES['uploadedfile']['name'];  
      $target_path = $target_path . basename($folderName); 

      //upload file 
      if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path."/")) { 
       echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded"; 
      } else{ 
       echo "There was an error uploading the file, please try again!"; 
      } 


      $zip = new ZipArchive; 
     $res = $zip->open($target_path); 


      $target_path = str_replace(".zip", "", $target_path); 

      echo $target_path; 

    if ($res === TRUE) { 
     $zip->extractTo($target_path."/"); 
     $zip->close(); 
     echo "ok"; 
    } else { 
     echo "failed"; 
    } 
+1

似乎問題不在於Joomla,而是在PHP中。我用上面的代碼創建了一個簡單的文件,我用它來上傳一個大小爲5MB的文件,但它需要很長時間,並且失敗。 – themis 2012-02-24 19:54:31

回答

0

在處理文件上傳時,有很多因素需要考慮。這些措施包括PHP設置:

  • max_input_time設置
  • 的max_execution_time
  • 的upload_max_filesize
  • 的post_max_size

執行時間會影響上傳例如如果你有導致超時緩慢的上傳速度。

如果您的文件大小+其他帖子數據超過post_max_size,上傳量大於upload_max_filesize,則文件大小可能會導致問題。

Zip在歸檔/提取過程中使用了大量內存,並且很容易超過分配給PHP的內存 - 所以這也值得檢查。

我會從this頁開始,並注意一些評論。

+0

thanx爲您的答案,但沒有任何幫助。我有 max_input_time設置= 60 的max_execution_time = 30 的upload_max_filesize = 110M 的post_max_size = 8MB 我試圖上傳的文件就像574KB(我做出了最後的測試)。 另外我在apache根目錄下創建了一個測試項目,以測試php的上傳功能,但它仍然很慢。它似乎與apache或php上的一些設置有關。仍然不能解決問題 – themis 2012-02-25 07:40:49

+0

我的UNIX服務器上,我承載該文件似乎工作正常和快速相同的代碼。它在我的Windows機器上遇到了問題。 – themis 2012-02-25 08:21:45

+0

我很驚訝,我使用谷歌瀏覽器進行了測試,我查看了谷歌瀏覽器的底部,當我開始上傳時,發生了一個進度%,並且所有內容看起來都很好。 Firefox正在上傳時發生問題。因此,我必須接受你的回答,因爲這很有幫助。感謝名單 – themis 2012-02-25 09:25:50