2016-09-19 134 views
0

我想將圖像文件上傳到網絡服務器。我正在使用Yii2框架。我可以毫無問題地上傳小文件,而如果我正在上傳大文件,則無法上傳。當文件上傳時,我可以在瀏覽器中看到進度條。但文件上傳完成後,文件不會保存在服務器上,瀏覽器也會顯示空白屏幕而不是index.php,但在日誌文件中會記錄調試消息(檢查點1 **)。Yii2文件上傳不適用於大文件

這裏是代碼片段供您參考。

 if ($model->load($_POST) && $model->save()) { 
     $arrFile = UploadedFile::getInstance($model, 'file_location'); 
     if (!empty($arrFile)) { 
      $model->file_location = $arrFile; 
      $strFileName = $model->file_location->baseName . '.' . $model->file_location->extension; 
      Yii::error('Check point 1 ************* '. $strFileName); 
      if ($model->file_location->saveAs('uploads/newsletters/' . $strFileName)) { 
       $model->file_location = $strFileName; 
       $model->save(); 
       return $this->redirect('index'); 
       //return $this->redirect(['view', 'id' => $model->id]); 
      } 
     } else { 
      return $this->redirect('index'); //$this->redirect(['view', 'id' => $model->id]); 
     } 
    } else { 
     return $this->render('create', [ 
        'model' => $model, 
     ]); 
    } 
+0

您可以檢查您的服務器的最大文件上傳大小嗎? –

+0

@ManikandanS:我沒有在代碼中指定任何大小限制。還有可用磁盤空間超過5GB。 –

+0

您必須按照下面的答案關注@MoneerKamal指令,更改值後請重新啓動apache服務器。 –

回答

0

請在你的php.ini檢查這

upload_max_filesize = 64M 

並編輯爲您需要的大小寫

+0

@Manikandan和Moneer:感謝您的支持。此解決方案工作。不知何故,這個參數沒有反映在我的共享Web服務器上,但在服務器團隊的幫助下,我將它從2M改爲了5M。我試圖上傳的文件是2.6M。再次感謝。 –

0

你需要在php.ini更改此:

max_execution_time = 30 

或者

在你的PHP腳本:

set_time_limit(180); // Set max execution time 3 minutes.