我们目前正在尝试为Yii使用扩展名eajaxupload,但每当我们尝试上传文件时,它似乎输出失败。
我们已经尝试了
a)编辑文件/最小文件大小
b)玩弄文件路径(可能仍然不正确,如果有人知道在xampp中本地使用的路径是什么,请告诉我们。我们的uploads文件夹位于项目的根目录中。)
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); }"
)*
答案 0 :(得分:0)
很久以前我遇到了同样的问题。 你必须确保:
答案 1 :(得分:0)
在我看来,你的行动在
中是错误的'config'=>array(
'action'=>'/upload/',
如果您要上传到public function actionUpload()
然后您的操作必须是'上传/上传'因为ConrollerName / ActionName必须匹配' action'在你的小部件
'config'=>array(
'action'=> Yii::app()->baseUrl . '/upload/upload',
或
'config'=>array(
'action'=>$this->createUrl('upload/upload')
请看一下:http://www.yiiframework.com/doc/guide/1.1/en/topics.url
祝你好运答案 2 :(得分:0)
要更新它,它将无法在MAC上的本地服务器Xampp上运行。
它适用于我们的live dev服务器,但不适用于实时服务器。似乎扩展与服务器有关。缺乏文档,我想有一个修复,但它回答了很多问题代码如何正常但不起作用。