【问题标题】:eajaxupload in yii failesyii中的ajax上传失败
【发布时间】:2013-02-12 12:26:30
【问题描述】:

我在 yii 中尝试 ti 用户 eajaxupload 扩展(使用这篇文章:http://www.yiiframework.com/extension/eajaxupload

我想将图像上传并附加到控制器之一, 我试试这段代码: 在控制器中: *(我的控制器名称是:文章)*

public function actionUpload()
        {
    Yii::import("ext.EAjaxUpload.qqFileUploader");

        $folder= Yii::app()->baseUrl .'/uploads';// folder for uploaded files
        $allowedExtensions = array("jpg");//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);
        $result=htmlspecialchars(json_encode($result), ENT_NOQUOTES);

    $fileSize=filesize($folder.$result['filename']);//GETTING FILE SIZE
        $fileName=$result['filename'];//GETTING FILE NAME

        //echo $result;// it's array
    }

在 _form.php(用于控制器)中我有:

$this->widget('ext.EAjaxUpload.EAjaxUpload',
        array(
            'id'=>'uploadFile',
                'config'=>array(
                    'action'=>'/article/upload',
                    'allowedExtensions'=>array("jpg"),//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); }",

                    'showMessage'=>"js:function(message){ alert(message); }"
                    )
)); ?>

上传文件夹对所有人具有完全访问权限!, 但是当我推送上传文件并选择一个文件时总是出错:文件名,文件大小和失败!

我的代码有什么问题?

【问题讨论】:

    标签: upload yii-extensions


    【解决方案1】:

    当你添加这个时,你在控制台上看到了什么

    echo "<pre>";
    print_r($result);
    echo "</pre>";exit(0);
    

    $result=htmlspecialchars(json_encode($result), ENT_NOQUOTES);之后

    【讨论】:

    • 我有同样的问题,这里是控制台输出 POST 请求:qq.extend._upload fileuploader.js:1204 qq.UploadHandlerAbstract.upload fileuploader.js:892 qq.FileUploaderBasic._uploadFile fileuploader.js :397 qq.FileUploaderBasic._uploadFileList fileuploader.js:388 qq.FileUploaderBasic._onInputChange fileuploader.js:372 qq.UploadButton.onChange fileuploader.js:309 (匿名函数)
    • 然后我得到一个 get 请求,输出如下 send jquery.js:8434 jQuery.extend.ajax jquery.js:7986 reloadImagesArea 551?required=1:934 qq.FileUploader.onComplete 551?required =1:1109 qq.(匿名函数).onComplete fileuploader.js:333 qq.extend._onComplete fileuploader.js:1230 xhr.onreadystatechange
    【解决方案2】:

    确保您的上传文件夹存在。 Yii::app()->baseUrl 返回 '...yourproject/protected'。

    我用:$folder=Yii::app() -&gt; getBasePath() . "/../images/";

    同时在浏览器中检查您的控制台(按 F12)。如果您遇到 403 错误,则将规则添加到您的控制器以进行上传操作

        public function accessRules()
        {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('index','view','upload'),
                'users'=>array('*'),
            ), 
         .....
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-15
      相关资源
      最近更新 更多