九英寸尼克/eajaxupload

利用文件上传器js库通过AJAX上传文件而不使用Flash的Yii PHP框架扩展。

此包的规范仓库似乎已消失,因此该包已被冻结。

安装: 1,611

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 15

语言:JavaScript

1.0.0 2014-11-04 15:09 UTC

This package is not auto-updated.

Last update: 2021-06-21 11:19:01 UTC


README

这个Yii PHP框架扩展允许使用AJAX上传文件而不使用Flash。

安装

经典

  • 下载 (zip, tar.gz)。
  • 解压到文件夹 application.extensions.EAjaxUpload。其内容应如下所示
protected/
├── components/
├── controllers/
├── ... application directories
└── extensions/
    ├── EAjaxUpload/
    │   ├── assets/
    │   └── ... other files of the EAjaxUpload extension
    └── ... other extensions

Composer

  • 运行: composer require nineinchnick/EAjaxUpload

使用

在视图/模板中使用小部件如下

<? $this->widget('application.vendor.nineinchnick.eajaxupload.EAjaxUpload', array(
    'id'=>'EAjaxUpload',
    'config'=>array(
        'action'=>$this->createUrl('files/uploadByAjax'),
        'template'=>'<div class="qq-uploader"><div class="qq-upload-drop-area"><span>Drop files here to upload</span></div><div class="qq-upload-button">Upload a file</div><ul class="qq-upload-list"></ul></div>',
        'debug'=>false,
        'allowedExtensions'=>array('jpg'),
        '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); }"
    )
)); ?>

将上传操作添加到控制器中

    public function actions()
    {
        return array(
            'upload'=>array(
                'class' => 'application.vendor.nineinchnick.eajaxupload.EAjaxUpload',
                'save' => array(
                    'modelClass' => 'EventAttachments',
                    'foreignKey' => 'event_id',
                ),
                'delete' => array(
                    'modelClass' => 'EventAttachments',
                    'foreignKey' => 'event_id',
                ),
            )
        );
    }

请记住,为上传操作禁用CSRF验证。

资源