


PHP imitates WeChat multiple image preview and upload function
Production picture area, upload button#btn can replace the picture you want
[html] view plain copy
View the code piece on CODE and derive it from my code piece
<ul id="ul_pics" class="ul_pics clearfix"> <li><img src="logo.png" id="btn" class="img_common" /></li> </ul>
plupload upload
[javascript] view plain copy
View the code piece on CODE derived to my code piece
var uploader = new plupload.Uploader({//创建实例的构造方法 runtimes: 'html5,flash,silverlight,html4', //上传插件初始化选用那种方式的优先级顺序 browse_button: 'btn', // 上传按钮 url: "ajax.php", //远程上传地址 flash_swf_url: 'plupload/Moxie.swf', //flash文件地址 silverlight_xap_url: 'plupload/Moxie.xap', //silverlight文件地址 filters: { max_file_size: '10mb', //最大上传文件大小(格式100b, 10kb, 10mb, 1gb) mime_types: [//允许文件上传类型 {title: "files", extensions: "jpg,png,gif,jpeg"} ] }, multi_selection: true, //true:ctrl多文件上传, false 单文件上传 init: { FilesAdded: function(up, files) { //文件上传前 if ($("#ul_pics").children("li").length > 30) { alert("您上传的图片太多了!"); uploader.destroy(); } else { var li = ''; plupload.each(files, function(file) { //遍历文件 li += "<li id='" + file['id'] + "'><p class='progress'><span class='bar'></span><span class='percent'>0%</span></p></li>"; }); $("#ul_pics").prepend(li); uploader.start(); } }, UploadProgress: function(up, file) { //上传中,显示进度条 var percent = file.percent; $("#" + file.id).find('.bar').css({"width": percent + "%"}); $("#" + file.id).find(".percent").text(percent + "%"); }, FileUploaded: function(up, file, info) { //文件上传成功的时候触发 var data = eval("(" + info.response + ")");//解析返回的json数据 $("#" + file.id).html("<input type='hidden'name='pic[]' value='" + data.pic + "'/><input type='hidden'name='pic_name[]' value='" + data.name + "'/><img class='img_common' onclick=delPic('" + data.pic + "','" + file.id + "') src='" + data.pic + "'/>");//追加图片 }, Error: function(up, err) { //上传出错的时候触发 alert(err.message); } } }); uploader.init();
ajax delete uploaded image
[ javascript] view plain copy
View the code piece on CODE derived from my code piece
function delPic(pic, file_id) { //删除图片 参数1图片路径 参数2 随机数 if (confirm("确定要删除吗?")) { $.post("del.php", {pic: pic}, function(data) { $("#" + file_id).remove() }) } }
PHP imitation WeChat multi-image preview download demo address: http://www.php.cn/
Production image area, upload button #btn can replace what you want The picture you want
[html] view plain copy
View the code piece on CODE Derived to my code piece
<ul id="ul_pics" class="ul_pics clearfix"> <li><img src="logo.png" id="btn" class="img_common" /></li> </ul>
plupload upload
[javascript] view plain copy
View the code piece derived from CODE to my code piece
var uploader = new plupload.Uploader({//创建实例的构造方法 runtimes: 'html5,flash,silverlight,html4', //上传插件初始化选用那种方式的优先级顺序 browse_button: 'btn', // 上传按钮 url: "ajax.php", //远程上传地址 flash_swf_url: 'plupload/Moxie.swf', //flash文件地址 silverlight_xap_url: 'plupload/Moxie.xap', //silverlight文件地址 filters: { max_file_size: '10mb', //最大上传文件大小(格式100b, 10kb, 10mb, 1gb) mime_types: [//允许文件上传类型 {title: "files", extensions: "jpg,png,gif,jpeg"} ] }, multi_selection: true, //true:ctrl多文件上传, false 单文件上传 init: { FilesAdded: function(up, files) { //文件上传前 if ($("#ul_pics").children("li").length > 30) { alert("您上传的图片太多了!"); uploader.destroy(); } else { var li = ''; plupload.each(files, function(file) { //遍历文件 li += "<li id='" + file['id'] + "'><p class='progress'><span class='bar'></span><span class='percent'>0%</span></p></li>"; }); $("#ul_pics").prepend(li); uploader.start(); } }, UploadProgress: function(up, file) { //上传中,显示进度条 var percent = file.percent; $("#" + file.id).find('.bar').css({"width": percent + "%"}); $("#" + file.id).find(".percent").text(percent + "%"); }, FileUploaded: function(up, file, info) { //文件上传成功的时候触发 var data = eval("(" + info.response + ")");//解析返回的json数据 $("#" + file.id).html("<input type='hidden'name='pic[]' value='" + data.pic + "'/><input type='hidden'name='pic_name[]' value='" + data.name + "'/><img class='img_common' onclick=delPic('" + data.pic + "','" + file.id + "') src='" + data.pic + "'/>");//追加图片 }, Error: function(up, err) { //上传出错的时候触发 alert(err.message); } } }); uploader.init();
ajax delete uploaded image
[javascript] view plain copy
View the code piece derived from CODE Go to my code piece
function delPic(pic, file_id) { //删除图片 参数1图片路径 参数2 随机数 if (confirm("确定要删除吗?")) { $.post("del.php", {pic: pic}, function(data) { $("#" + file_id).remove() }) } }
For more PHP imitating WeChat multi-picture preview and upload functions, please pay attention to the PHP Chinese website for related articles!

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

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
