yixianliu2

yixianliu2

这家伙有点懒,还没写个性签名!

  • 财富值505
  • 威望值0
  • 总积分615

个人信息

  • 2017-09-22 已签到
    连续签到1天,获得了5个金钱
  • 2017-01-09 已签到
    连续签到1天,获得了5个金钱
  • 2016-12-22 已签到
    连续签到1天,获得了5个金钱
  • 2016-12-20 已签到
    连续签到1天,获得了5个金钱
  • 2016-12-18 已签到
    连续签到1天,获得了5个金钱
  • 2016-12-16 已签到
    连续签到1天,获得了5个金钱
  • 回复了 的回答

    首先看下github中的说明
    配置跳过
    然后是向html类中添加此插件

    namespace app\components;
    
    use yii\helpers\Html as BaseHtml;
    use sweelix\yii2\plupload\traits\Plupload;
    
    class Html extends BaseHtml
    {
        // adding this trait allow easy access to plupload
        use Plupload;
    }
    

    这里在类中use Plupload;
    他映射的类是插件下/traits/Plupload.php
    看下这个文件的代码可以找到使用时的

    echo Html::asyncInput('demoUpload', isset($_POST['demoUpload'])?$_POST['demoUpload']:null, ['config' => [
            'ui' => true,
            'auto' => true,
        ]]); ?>
    

    asyncInput方法

     /**
         * Create an asynchronous file upload.
         * Plupload specific configuration should be set in $options['config']
         * The $options['config']['ui'] can be :
         *  * false // no ui
         *  * true  // basic ui
         *  * Javascript object (passed in Jsexpression). Everything is handled by the developper
         *
         * @param  string       $name    name of the input (append [] for multifile upload)
         * @param  string|array $value   the file(s) already uploaded (array for multifile upload)
         * @param  array        $options @see static::input()
         *
         * @return string
         * @since  1.0.0
         */
        public static function asyncInput($name, $value = null, $options = [])
        {
            // prepare data
            $originalName = $name;
            if (is_array($value) === true) {
                $value = array_filter($value, function ($el) { return !empty($el); });
            }
            if (empty($value) === true) {
                $value = null;
            }
            // prepare option data
            $options['name'] = $name;
            $options['config']['multiSelection'] = false;
            if (isset($options['id']) === false) {
                $options['id'] = self::getIdByName($name);
            }
            // remove the trailing [] which is just annoying except to send multiple files
            // we rely on [] to define the multiple file upload
            if (substr($name, -2) === '[]') {
                $originalName = substr($name, 0, -2);
                $options['config']['multiSelection'] = true;
                if ($value !== null) {
                    if (is_array($value) === false) {
                        // force array for multifile
                        $value = [$value];
                    }
                    $value = array_map(function ($el) {
                        // remove everything which is path related. It must be handled by the developper / model
                        return pathinfo(trim($el), PATHINFO_BASENAME);
                    }, $value);
                }
            } else {
                if ($value !== null) {
                    $value = pathinfo((string)$value, PATHINFO_BASENAME);
                }
            }
            if ($value !== null) {
                // we must retrieve original data
                $instances = UploadedFile::getInstancesByName($originalName);
                // force check with arrays
                $affectedFiles = (is_array($value) === true)?$value:[$value];
                //translate everything into UploadedFile(s)
                $translatedValues = [];
                foreach ($instances as $instance) {
                    if (in_array($instance->name, $affectedFiles) === true) {
                        $affectedFilesKeys = array_keys($affectedFiles, $instance->name);
                        unset($affectedFiles[$affectedFilesKeys[0]]);
                        $translatedValues[] = $instance;
                    }
                }
                foreach ($affectedFiles as $remainingFile) {
                    // we are looking at already saved files. Reinit as expected
                    $translatedValues[] = new UploadedFile([
                        'name' => $remainingFile,
                        'tempName' => null,
                        'type' => 'application/octet-stream',
                        'size' => null,
                        'error' => 0,
                    ]);
                }
                $value = $translatedValues;
                if ($options['config']['multiSelection'] === false) {
                    // get first value in case we are not multi
                    $value = array_pop($value);
                }
            }
            $config = static::prepareAsyncInput($options);
            return static::renderAsyncInput($value, $options, $config);
        }
    
     * @param  string       $name    name of the input (append [] for multifile upload)
     * @param  string|array $value   the file(s) already uploaded (array for multifile upload)
     * @param  array        $options @see static::input()
    

    asyncInput($name, $value = null, $options = [])
    看方法的参数说明
    第一个参数是插件的name名称
    第二个参数就是你所需要的已上传文件显示
    单个文件传入文件路径字符串
    多个文件传入路径数组
    第三个参数不用多说,当前html元素要附件的属性
    这样明白了吗?这个插件我没用过,不知道是否好用?

    第二个参数的确可以显示出上传图片名称(就是显示了 '5s.jpg')了,但是问题是,图片地址为undefined,无法正常显示图片,很奇怪,我已经传入文件路径地址了...

    '../views/default/themes/images/pictures/5s.jpg' 地址有效..

  • 提出了问题
    YII2上传插件Plupload疑问?
  • 2016-12-14 已签到
    连续签到1天,获得了5个金钱
  • 2016-12-11 已签到
    连续签到1天,获得了5个金钱
主管 等级规则
615/1000
资料完整度
40/100
用户活跃度
0/100

Ta的关注

0

Ta的粉丝

0

Ta的访客

6