<link rel="stylesheet" type="text/css" href="__PUBLIC__/uploadimg/js/uploadify-v3.1/uploadify.css" media="all">
<script type="text/javascript" src="__PUBLIC__/uploadimg/js/uploadify-v3.1/jquery.uploadify-3.1.min.js"></script>
当然也必须引入:jquery库文件<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'swf' : '__PUBLIC__/uploadimg/js/uploadify-v3.1/uploadify.swf',
'uploader' : '{:U("Student/uploadify")}',
'buttonText' : '上传头像',
'onUploadSuccess' : function(file, data, response) {
$('#image').attr('src','/Uploads/images/130_'+data);
$('#pic').val(data);
},
});
});
</script>
5、上传表单:<div class="unit">
<label>照片:</label>
<img id="image" src="__PUBLIC__/uploadimg/js/mystery.png" width="130" height="130" border="0" />
<input id="file_upload" name="file_upload" type="file" multiple="true" value="" />
<input id="pic" name="photo" type="hidden" />
</div>
6、上传函数: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 = "./Uploads/images/";
$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 $info[0]['savename']; //返回文件名给JS作回调用
}
}
thinkphp上传图片示例.zip ( 61.73 KB 下载:788 次 )