dongxiang3205 2011-12-17 09:46
浏览 42
已采纳

如何使用Yii的xupload

I am new to Yii and want to integrate file uploading.Unfortunately I have not been able to make it work.I have downloaded and extracted the plugin to /extensions/ folder but now I do not know what to do.

Can some one guide me?

here is the link for extension

http://www.yiiframework.com/extension/xupload/

  • 写回答

2条回答 默认 最新

  • dongxian6653 2011-12-17 10:01
    关注

    that extension is outdated and poorly supported. I use this extension instead: eajaxupload.

    As you can see on that page the usage is extremely simple. Upload it to your extensions dir and install it with these few lines of code

    First you put the following code in your controller action:

    public function actionUpload()
    {
            Yii::import("ext.EAjaxUpload.qqFileUploader");
    
            $folder='upload/';// 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
    }
    

    After that go to the associated view file for that action and use this code to generate the upload form:

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

    Extremely easy to get working. Give it a go!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路