《五》uploadify插件上传文件

来源:互联网 发布:常用医学软件 编辑:程序博客网 时间:2024/05/15 03:06

下载地址:http://www.uploadify.com/wp-content/uploads/files/uploadify.zip
相关配置:http://www.uploadify.com/documentation/

一、 html 上传页面:

<!doctype html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title>    <link rel="stylesheet" href="__STATIC__/static/uploadify/uploadify.css"/></head><body><input type="file" name="file_upload" id="file_upload" /><img id="img" src=""/></body><script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script><script src="__STATIC__/static/uploadify/jquery.uploadify.min.js"></script><script>    $(function() {        $("#file_upload").uploadify({            'swf'             : '__STATIC__/static/uploadify/uploadify.swf',            'uploader'        : '{:url("/file")}',            'fileObjName'     : 'the_files',            'buttonText'      : '图片上传',            'onUploadSuccess' : function(file, data, response) {                if(response){                    var obj=JSON.parse(data);                    $('#img').attr('src',obj.data);                    $('#img').attr('width','200px;');                    $('#img').attr('height','200px;');                }            }        });    });</script></html>

二、路由文件:

<?phpuse think\Route;//上传页面Route::rule('map','index/Index/index','GET');//接受上传页面Route::rule('file','api/Upload/index','POST');

三、api/Upload/index 方法:

<?phpnamespace app\api\controller;use think\Controller;use think\Request;class Upload extends Controller{    public function index()    {        $file=request()->file('the_files');        $info = $file->move('uploads');        if($info){            return [                'status'=> 1,                'message'=>'success',                'data'=>DS.$info->getPathname()            ];        }else{            // 上传失败获取错误信息            echo $file->getError();        }    }}

效果:

这里写图片描述

结束。