0

I try ti user eajaxupload extention in yii(using this article: http://www.yiiframework.com/extension/eajaxupload

I want Upload and attache image to one of controller, I try this code: in controller: *(my controller name is : article)*

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
    }

and in _form.php (for controller) i have:

$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 folder have full access for all!, but when i push upload file and select a file always get error: filename, filesize and Faild!

What is wrong in my code?

4

2 回答 2

0

添加此内容时,您在控制台上看到了什么

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

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

于 2013-03-09T00:49:05.593 回答
0

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

我用:$folder=Yii::app() -> 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('*'),
        ), 
     .....
于 2014-05-09T22:34:18.667 回答