2015-06-10 55 views
0

我正在用Yii使用blueimp文件上傳插件嘗試上傳文件到我的服務器(當前爲localhost)。我給了文件夾完整的讀/寫權限(位置是C:\ xampp \ htdocs \ yii),但是當我嘗試執行move_uploaded file命令時仍然出現錯誤。Yii不會move_uploaded_file - 500內部服務器錯誤

這裏是主要形式,並輸入文件區:

<form id='upload' method='post' action='?r=site/move' enctype='multipart/form-data' style="padding:0;"> 
    <span class="btn fileinput-button" style="padding:0"> 
     <i class="glyphicon glyphicon-picture"> 
      <input id="fileupload" type="file" accept="image/*" name="attachment" onchange="attachAttachment()"> 
     </i>           
    </span> 
</form> 

這裏是blueimp的文件上傳(函數()):

$("#fileupload").fileupload 
({ 

     dataType: 'json', 

     done: function (e, data) 
     { 
      console.log("YAY"); 
     }, 

     fail: function(e, data) 
     { 
      console.log("FAIL"); 
     } 
}); 

這裏是actionMove,在這裏我將文件從移動臨時目錄到該文件夾​​:

public function actionMove() 
{ 
    if (isset($_FILES['attachment']) && $_FILES['attachment']['error'] == 0) 
    {   
     if (move_uploaded_file($_FILES['attachment'], Yii::getPathOfAlias('webroot')."/images/uploads")){ 
      $response = '{"status":"success"}'; 
     } 
     else { 
      $response = '{"status":"error"}'; 
     } 

     echo $response; 
     exit(); 
    } 
} 

我一直在這裏幾個小時了,任何幫助表示讚賞:(

回答

0

$_FILES['attachment']參考有關下載的所有數據。 move_uploaded_file使用文件名工作。下面是你應該嘗試什麼:

$uploadPath = Yii::getPathOfAlias('webroot')."/images/uploads"; 
$uploadFilename = basename($_FILES['attachment']['name']); 
$tempFilename = $_FILES['attachment']['tmp_name']; 
$ok = move_uploaded_file($tempFilename, $uploadPath.'/'.$uploadFilename); 
if ($ok) { 
    $response = '{"status":"success"}'; 
} else { 
    $response = '{"status":"error"}'; 
} 

更多關於此的文檔頁面: http://php.net/manual/fr/features.file-upload.post-method.phphttp://php.net/manual/fr/function.move-uploaded-file.php

希望它能幫助。