


Use ThinkPHP+Uploadify to implement image upload function_PHP tutorial
First, unzip the downloaded Uploadify compressed package and place it in the public folder. The implementation code is as follows:
Frontend html part:
<script src="/uploadify/jquery.min.js" data-ke-src="/Public/uploadify/jquery.min.js" type="text/javascript"> <script src="/uploadify/jquery.uploadify.min.js" data-ke-src="/Public/uploadify/jquery.uploadify.min.js" type="text/javascript"> <link rel="stylesheet" type="text/css" href="/uploadify/uploadify.css" data-ke-src="/Public/uploadify/uploadify.css"> <script type="text/javascript"> var img_id_upload=new Array();//初始化数组,存储已经上传的图片名 var i=0;//初始化数组下标 $(function() { $('#file_upload').uploadify({ 'auto' : false,//关闭自动上传 'removeTimeout' : 600,//文件队列上传完成1秒后删除 'swf' : '/Public/uploadify/uploadify.swf', 'uploader' : '/_URL_/Article/uploadify', 'method' : 'post', //方法,服务端可以用$_POST数组获取数据 'buttonText' : '选择图片',//设置按钮文本 'multi' : true,//允许同时上传多张图片 'uploadLimit' : 8,//一次最多只允许上传10张图片 'fileTypeDesc' : 'Image Files',//只允许上传图像 'fileTypeExts' : '*.gif; *.jpg; *.png',//限制允许上传的图片后缀 'fileSizeLimit' : '2000KB',//限制上传的图片大小 'onUploadSuccess' : function(file, data, response) { //每次成功上传后执行的回调函数,从服务端返回数据到前端 $('#image').append('<div style="float:left;margin:2px 0 0 2px"><img width="100px" height="100px" src="/uploads/'+data+'" data-ke-src="/uploads/'+data+'" height=80 width=80 />'); img_id_upload[i]=data; i++; } }); }); </script> <input type="file" name="file_upload" id="file_upload" /> <p><a href="javascript:$('#file_upload').uploadify('upload','');" data-ke-src="javascript:$('#file_upload').uploadify('upload','');">上传</a> </p> <br /> <div id="image" class="image"><br />
action execution code part:
public function uploadify() { $ph=M('Upload'); import('ORG.Net.UploadFile'); $upload = new UploadFile();// 实例化上传类 $upload->maxSize = 93145728 ;// 设置附件上传大小 $upload->saveRule =rand(1,9999); $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg','flv','avi','mov');// 设置附件上传类型 $upload->savePath = './Uploads/';// 设置附件上传目录 if(!$upload->upload()) {// 上传错误提示错误信息 $this->error($upload->getErrorMsg()); }else{// 上传成功 获取上传文件信息 $info = $upload->getUploadFileInfo(); } for($i=0;$i<count($info);$i++) { $data['name']=$info[$i]['savename']; $data['size']=$info[$i]['size']; $data['type']=$info[$i]['extension']; echo $info[$i]['savename']; $rs=$ph->add($data); } /*if($rs) { $this->success("成功"); }else { $this->error("失败"); }*/ }

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

Development suggestions: How to use the ThinkPHP framework for API development. With the continuous development of the Internet, the importance of API (Application Programming Interface) has become increasingly prominent. API is a bridge for communication between different applications. It can realize data sharing, function calling and other operations, and provides developers with a relatively simple and fast development method. As an excellent PHP development framework, the ThinkPHP framework is efficient, scalable and easy to use.
