下载地址: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>
二、路由文件:
<?php
use think\Route;
//上传页面
Route::rule('map','index/Index/index','GET');
//接受上传页面
Route::rule('file','api/Upload/index','POST');
三、api/Upload/index 方法:
<?php
namespace 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();
}
}
}