uploadify版本 3.2.1
在使用中如果有什么版本上的更新小改动,请自行查看官方手册修改哟!
前台页代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>thinkphp 3.1系列+ uploadify demo</title>
<link rel="stylesheet" href="">
</head>
<body>
<h1>thinkphp 3.1系列+ uploadify demo</h1>
<form action="{:U('index')}" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<div class="avtor" style="width: 200px; height: 200px; background: gray;">
<img id="head_icon" src="" width="100%" height="100%" alt="">
</div>
<div class="touxiang">
<input id="file_upload" type="text" name="touxiang">
</div>
<div class="touxiang_path">
<input id="" type="text" name="touxiang_path" class="touxiang_path" style="width: 500px;">
</div>
</form>
<!--引用jquery uploady*}-->
<script src="__PUBLIC__/jquery.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/uploadify.css" media="all">
<script type="text/javascript" src="__PUBLIC__/jquery.uploadify.min.js"></script>
<!-- uploadify相关设置 -->
<script type="text/javascript">
<?php $timestamp = time();?>
$(function() {
$('#file_upload').uploadify({
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},//在php下应用的时候请务必加上这些代码,避免使用出错
'buttonText':'上传',
'multi': true,//允许多文件上传
'swf' : "__PUBLIC__/uploadify.swf",
'uploader' : '{:U("uploadify")}',
'onUploadSuccess': function (file, data, response) {
$('#head_icon').attr('src',data);
$('.touxiang_path').val(data);
}
});
});
</script>
</body>
</html>后台处理代码<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
$this->display();
}
//接收前台提交的数据,并一步上传到服务器,返回相应的ajax数据
public function uploadify(){
if (!empty($_FILES)) {
import("ORG.NET.UploadFile");
$upload = new UploadFile();
$upload->maxSize = 2048000;
$upload->allowExts = array('jpg','jpeg','gif','png');
$upload->savePath = "./upload/qq571031767/";
$upload->thumb = true; //设置缩略图
$upload->imageClassPath = "ORG.Util.Image";
$upload->thumbPrefix = "130_,75_"; //生成多张缩略图
$upload->thumbMaxWidth = "130,75";
$upload->thumbMaxHeight = "130,75";
$upload->saveRule = uniqid; //上传规则
$upload->thumbRemoveOrigin = true; //删除原图
if(!$upload->upload()){
$this->error($upload->getErrorMsg());//获取失败信息
} else {
$info = $upload->getUploadFileInfo();//获取成功信息
}
echo 'http://'.$this->_server('HTTP_HOST').__ROOT__.'/upload/qq571031767/130_'.$info[0]['savename'];
}else{
echo 'error';
}
}
}全部demo下载链接链接:http://pan.baidu.com/s/1hrSBrpE 密码:4dho用的是thinkphp的完全包 略微有点大~ 大家喜欢 下下来后可以自己做精简
