dream5694 2015-05-29 11:44
浏览 29

你总是“失败”的ajaxupload

We are currently trying to use the extension eajaxupload for Yii but it seems to be outputting failed everytime we try to upload a file.

We have tried

a) editing the file / minimum file sizes

b) playing around with the file path (may still be incorrect, if anyone knows what the path for locally using in xampp would be, let us know. Our uploads folder is in the root of the project.)

c) changing the htiaccess php file

d) permissions

we just don't know if the code itself is appearing wrong.

controller

/* 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
    }

View

*$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); }"

                    )*
  • 写回答

3条回答 默认 最新

  • douzen1880 2015-05-31 10:52
    关注

    I got the same problem long ago. You have to make sure that:

    • you get the local path, not url (Yii::getPathOfAlias('webroot')).
    • the $sizeLimit has to be less than the php options 'post_max_size' and 'upload_max_size'. You can check their values with ini_get(variable) and convert it to Bytes.
    • Also noticed that you are trying to upload the file twice.
    • If none of them work post the error message that you are getting.
    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗