


How to upload images through WeChat WEUI, how to handle it in background PHP?
Question: How to upload images through WeChat WEUI, how should the background PHP handle it?
1. The problem currently encountered is the application's weui image upload framework, but the preview part li in the code obtains images of type blob. But there is only one input, submitted to php through ajax, and only the last picture can be obtained.
<p class="weui-uploader__bd"> <ul class="weui-uploader__files" id="uploaderFiles" > <li class="weui-uploader__file" style="background-image:url('/Public/Admin/images/pic_160.png')"></li> <li class="weui-uploader__file weui-uploader__file_status" style="background-image:url('/Public/Admin/images/pic_160.png')"> <p class="weui-uploader__file-content">50%</p> </li> </ul> <p class="weui-uploader__input-box"> <input id="uploaderInput" name="photo" class="weui-uploader__input" type="file" accept="image/*" /> </p> </p>
2. Only one input can be obtained through $_FILES in the background. How can I get them all? How do you handle uploading pictures using weui?
When pasting a photo without adding [], what you get is
Add [] and what you get back is:
Solution
//解决思路如下: 通过改写他的文件隐藏域,每次选择一个图片之后,自动隐藏当前file,然后通过js插入一个新的空文件 type=“file”,这样就可以实现多文件上传。改写代码如下: $(function(){ var tmpl = '<li id="#imgname#_li" class="weui-uploader__file" style="background-image:url(#url#)"></li>', $gallery = $("#gallery"), $galleryImg = $("#galleryImg"), $uploaderInput = $("#uploaderInput"), $uploaderFiles = $("#uploaderFiles") ; //此处的on 需要改成 live ,因为jquery插入html,js事件会失效,采用live $uploaderInput.live("change", function(e){ var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files; for (var i = 0, len = files.length; i < len; ++i) { var file = files[i]; if (url) { src = url.createObjectURL(file); } else { src = e.target.result; } var src_split = src.split('/'); $uploaderFiles.append($(tmpl.replace('#url#', src).replace('#imgname#', src_split[src_split.length-1]))); //其中img_str 为我自己写的隐藏文本框,用来存放所有的图片名称组成的字符,类似"'名称1','名称2','名称3'",因为我用这个隐藏框的值,来删除页面页面的指定图片。 if($("#img_str").val() == '' || $("#img_str").val() == null){ $("#img_str").val("'"+src_split[src_split.length-1]+"'"); }else{ $("#img_str").val($("#img_str").val()+",'"+src_split[src_split.length-1]+"'"); } //开启隐藏上传 p $(this).after('<input id="uploaderInput" name="result_file[]" class="weui-uploader__input" type="file" accept="image/*" multiple/>'); $(this).hide(); $(this).attr({id:""+src_split[src_split.length-1]+"_input"}); } }); $uploaderFiles.on("click", "li", function(){ $galleryImg.attr("style", this.getAttribute("style")); $gallery.fadeIn(100); }); $gallery.on("click", function(){ $gallery.fadeOut(100); }); //删除图片 删除图片的代码也贴出来。 $(".weui-gallery__del").click(function(){ var imgback = $(this).parent("p").prev().attr("style"); var imgback_array= imgback.split(')'); imgback_array= imgback_array[0].split('/'); $("#"+imgback_array[imgback_array.length-1]+"_input").remove(); $("#"+imgback_array[imgback_array.length-1]+"_li").remove(); var img_str = $("#img_str").val().split(','); var img_str_new = ''; for(var i=0;i<img_str.length;i++){ if(img_str[i] != "'"+imgback_array[imgback_array.length-1]+"'"){ if(img_str_new == ''){ img_str_new = img_str[i]; }else{ img_str_new = img_str_new+","+img_str[i]; } } } $("#img_str").val(img_str_new); }); }); /** 后台获取数打印出来 如下 包含3张图片 **/ array (size=2) 'error' => array (size=0) empty 'files' => array (size=3) 0 => array (size=14) 'file_name' => string 'e2dafa6a5f06dc34004607e1f00a4824.jpg' (length=36) 'file_type' => string 'image/jpeg' (length=10) 'file_path' => string 'E:/wamp/wamp/www/test/js/fileUpload/server/upload/tsjy/' (length=64) 'full_path' => string 'E:/wamp/wamp/www/test/js/fileUpload/server/upload/tsjy/e2dafa6a5f06dc34004607e1f00a4824.jpg' (length=100) 'raw_name' => string 'e2dafa6a5f06dc34004607e1f00a4824' (length=32) 'orig_name' => string '-0.jpg' (length=6) 'client_name' => string '6880_jpg_wh300.jpg' (length=18) 'file_ext' => string '.jpg' (length=4) 'file_size' => float 93.32 'is_image' => boolean true 'image_width' => int 960 'image_height' => int 300 'image_type' => string 'jpeg' (length=4) 'image_size_str' => string 'width="960" height="300"' (length=24) 1 => array (size=14) 'file_name' => string 'ba7a0cc5930d19c6b1abfd795b3eb4d3.jpg' (length=36) 'file_type' => string 'image/jpeg' (length=10) 'file_path' => string 'E:/wamp/wamp/www/test/js/fileUpload/server/upload/tsjy/' (length=64) 'full_path' => string 'E:/wamp/wamp/www/test/js/fileUpload/server/upload/tsjy/ba7a0cc5930d19c6b1abfd795b3eb4d3.jpg' (length=100) 'raw_name' => string 'ba7a0cc5930d19c6b1abfd795b3eb4d3' (length=32) 'orig_name' => string '-1.jpg' (length=6) 'client_name' => string '4856_jpg_wh300.jpg' (length=18) 'file_ext' => string '.jpg' (length=4) 'file_size' => float 92.95 'is_image' => boolean true 'image_width' => int 1190 'image_height' => int 300 'image_type' => string 'jpeg' (length=4) 'image_size_str' => string 'width="1190" height="300"' (length=25) 2 => array (size=14) 'file_name' => string 'fc0e75063c34f102a3a67fd17aa54a18.jpg' (length=36) 'file_type' => string 'image/jpeg' (length=10) 'file_path' => string 'E:/wamp/wamp/www/test/js/fileUpload/server/upload/tsjy/' (length=64) 'full_path' => string 'E:/wamp/wamp/www/test/js/fileUpload/server/upload/tsjy/fc0e75063c34f102a3a67fd17aa54a18.jpg' (length=100) 'raw_name' => string 'fc0e75063c34f102a3a67fd17aa54a18' (length=32) 'orig_name' => string '-2.jpg' (length=6) 'client_name' => string '4873_jpg_wh300.jpg' (length=18) 'file_ext' => string '.jpg' (length=4) 'file_size' => float 214.92 'is_image' => boolean true 'image_width' => int 1152 'image_height' => int 300 'image_type' => string 'jpeg' (length=4) 'image_size_str' => string 'width="1152" height="300"' (length=25)
Related articles:
Angularjs integrates WeChat UI (weui)
Encapsulation of JS common information prompt pop-up layers for WEUI applications

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment