ThinkPHP3.1.3图片上传实例
1、将上传和缩略图处理扩展放在TP核心中,直接覆盖压缩包中的ThinkPHP即可
2、下载jquery.uploadify插件 即文件包中的Public/uploadimg/js/uploadify-v3.1/
3、在上传页面模板引入js和css<link>
<br>
<script></script>
当然也必须引入:jquery库文件
4、在上传页面模板<script><br />
$(function() {<br />
$('#file_upload').uploadify({<br />
'swf' : '__PUBLIC__/uploadimg/js/uploadify-v3.1/uploadify.swf',<br />
'uploader' : '{:U("Student/uploadify")}',<br />
'buttonText' : '上传头像',<br />
'onUploadSuccess' : function(file, data, response) {<br />
$('#image').attr('src','/Uploads/images/130_'+data);<br />
$('#pic').val(data);<br />
},<br />
});<br />
});<br />
</script>
5、上传表单:<div>
<br>
<label>照片:</label><br>
<img src="/static/imghwm/default1.png" data-src="__PUBLIC__/uploadimg/js/mystery.png" class="lazy" alt="ThinkPHP图片上传实例" ><br>
<input><br>
<input><br>
</div>
6、上传函数:public function uploadify(){<br>
if (!empty($_FILES)) {<br>
import("ORG.NET.UploadFile");<br>
$upload = new UploadFile();<br>
$upload->maxSize = 2048000;<br>
$upload->allowExts = array('jpg','jpeg','gif','png');<br>
$upload->savePath = "./Uploads/images/";<br>
$upload->thumb = true; //设置缩略图<br>
$upload->imageClassPath = "ORG.Util.Image";<br>
$upload->thumbPrefix = "130_,75_"; //生成多张缩略图<br>
$upload->thumbMaxWidth = "130,75";<br>
$upload->thumbMaxHeight = "130,75";<br>
$upload->saveRule = uniqid; //上传规则<br>
$upload->thumbRemoveOrigin = true; //删除原图<br>
if(!$upload->upload()){<br>
$this->error($upload->getErrorMsg());//获取失败信息<br>
} else {<br>
$info = $upload->getUploadFileInfo();//获取成功信息<br>
}<br>
echo $info[0]['savename']; //返回文件名给JS作回调用<br>
}<br>
}
thinkphp上传图片示例.zip
( 61.73 KB 下载:855 次 )
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
