您的位置:首页 > 编程语言 > PHP开发

《五》uploadify插件上传文件

2017-06-11 16:58 399 查看
下载地址: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();
}
}

}


效果:



结束。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息