search
Homephp教程php手册ThinkPHP图片上传实例

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 /> $(&#039;#file_upload&#039;).uploadify({<br /> &#039;swf&#039; : &#039;__PUBLIC__/uploadimg/js/uploadify-v3.1/uploadify.swf&#039;,<br /> &#039;uploader&#039; : &#039;{:U("Student/uploadify")}&#039;,<br /> &#039;buttonText&#039; : &#039;上传头像&#039;,<br /> &#039;onUploadSuccess&#039; : function(file, data, response) {<br /> $(&#039;#image&#039;).attr(&#039;src&#039;,&#039;/Uploads/images/130_&#039;+data);<br /> $(&#039;#pic&#039;).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元

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use