我們目前正在嘗試爲Yii使用擴展eajaxupload,但每次我們嘗試上傳文件時似乎都輸出失敗。對於Yii,eajaxupload總是「失敗」
我們試圖
一)編輯文件/最小文件大小
b)與文件路徑玩耍(仍可能是不正確的,如果有人知道什麼地方使用XAMPP的路徑將是,讓我們知道,我們的上傳文件夾是在項目的根。)
c)改變的htiaccess PHP文件
d)權限
我們只是不知道代碼本身是否出現錯誤。
控制器
/* UPLOADER */
public function actionUpload(){
Yii::import("ext.EAjaxUpload.qqFileUploader");
// $folder = '/uploads/';
// $folder=Yii::getPathOfAlias() .'/upload/';
$folder=Yii::app()->baseUrl . '/uploads/';
$allowedExtensions = array("jpg","png");//array("jpg","jpeg","gif","exe","mov" and etc...
$sizeLimit = 10 * 1024 * 1024;// maximum file size in bytes
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload($folder);
// $return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
//
// $fileSize=filesize($folder.$result['filename']);//GETTING FILE SIZE
// $fileName=$result['filename'];//GETTING FILE NAME
//
// echo $return;// it's array
$result = $uploader->handleUpload($folder);
$fileSize=filesize($folder.$result['filename']);//GETTING FILE SIZE
$fileName=$result['filename'];//GETTING FILE NAME
$result=htmlspecialchars(json_encode($result), ENT_NOQUOTES);
echo $result;// it's array
}
查看
*$this->widget('ext.EAjaxUpload.EAjaxUpload',
array(
'id'=>'uploadFile',
'config'=>array(
'action'=>'/upload/',
// 'action'=>Yii::app()->createUrl('controllers/uploads/'),
'allowedExtensions'=>array("jpg","png"),//array("jpg","jpeg","gif","exe","mov" and etc...
'sizeLimit'=>10*1024*1024,// maximum file size in bytes
//'minSizeLimit'=>10*1024*1024,// minimum file size in bytes
'onComplete'=>"js:function(id, fileName, responseJSON){ alert(fileName); }",
'messages'=>array(
'typeError'=>"{file} has invalid extension. Only {extensions} are allowed.",
'sizeError'=>"{file} is too large, maximum file size is {sizeLimit}.",
'minSizeError'=>"{file} is too small, minimum file size is {minSizeLimit}.",
'emptyError'=>"{file} is empty, please select files again without it.",
'onLeave'=>"The files are being uploaded, if you leave now the upload will be cancelled."
),
'showMessage'=>"js:function(message){ alert(message); }"
)*
所以會:$ folder = Yii :: getPathOfAlias()。'/上傳/'; 然後'action'=>'/ upload /',是格式化的正確方法嗎?仍然沒有運氣!我們最初得到一個403錯誤,然後移動到400. – DevAL
你試過Yii :: getPathOfAlias('webroot')? 你能打印你得到的完整路徑嗎? –
是的,我確定webroot是我們在使用getpathofalias時嘗試的第一件事。似乎正在輸出的當前路徑是/ application/uploads/images/ – DevAL