


PHP Ajax JS implements multiple image uploads, ajax multiple images_PHP tutorial
Jul 12, 2016 am 08:53 AMPHP Ajax JS implements multi-image upload, ajax multi-image
The example in this article needs to do an ajax multiple image upload in the wap station project, and combined with the js plug-in to make one for everyone For reference, the specific content is as follows
/* ajax 上傳圖片 */ var num = 0; // 點擊刪除圖片 function onDelete(num){ if($("#"+num).attr('src')!="__PUBLIC__/Home/images/jiazai.gif" && $("#"+num).attr('src')!=""){ if(confirm("確認(rèn)刪除嗎")){ $("#a"+num).remove(); }else{ // } } } $(function(){ $("#file0").bind("change",function(){ clickUpload(num); }); function clickUpload(num){ var imgObject = document.getElementById('file0'); // 文件對象 $("#yulan").append("<a id='a"+num+"' onclick='onDelete("+num+")' href='javascript:;'> <img id='"+num+"' width='75' height='75' src='__PUBLIC__/Home/images/jiazai.gif'/></a>"); // $("#yulan").append("<li id='a"+num+"' ><img id='"+num+"' src='__PUBLIC__/Home/images/jiazai.gif' /><a href='javascript:;' onclick='onDelete("+num+")'>刪除</a></li>"); var getImageSrc = getFullPath(imgObject); // 本地路徑 // 實例化image對象 var pos = getImageSrc.lastIndexOf("."); var lastname = getImageSrc.substring(pos, getImageSrc.length) // 圖片后綴 if(lastname!=".jpg" && lastname!=".png" && lastname!=".jpeg" && lastname!='.gif'){ $("#a"+num).remove(); alert("請選擇一張圖片"); }else{ ajaxFileUpload(num); $("#file0").unbind("change").bind("change",function(){ clickUpload(num); }); } num++; } function getFullPath(obj) { //得到圖片的完整路徑 if (obj) { if (window.navigator.userAgent.indexOf("MSIE") >= 1) { obj.select(); return document.selection.createRange().text; }else if (window.navigator.userAgent.indexOf("Firefox") >= 1) { if (obj.files) { return obj.files.item(0).getAsDataURL(); } return obj.value; } return obj.value; } } function ajaxFileUpload(num) { $.ajaxFileUpload ( { url: 'http://xxxx/updateImg', //用于文件上傳的服務(wù)器端請求地址 secureuri: false, //是否需要安全協(xié)議,一般設(shè)置為false fileElementId: 'file0', //文件上傳域的ID dataType: 'json', //返回值類型 一般設(shè)置為json success: function (data) //服務(wù)器成功響應(yīng)處理函數(shù) { var jsonText = data; console.log(jsonText); if(jsonText['status']==1){ if(jsonText['info']!=""){ console.log(jsonText['info']); $("#"+num).attr("src","__PUBLIC__//Admin/Upload/"+jsonText['info']); var images = $("#img").val(); if(images!=""){ $("#img").val(images+","+jsonText['info']); }else{ $("#img").val(images+""+jsonText['info']); } } }else{ $("#a"+num).remove(); // alert("圖片上傳失敗"); } }, error: function (data,e)//服務(wù)器響應(yīng)失敗處理函數(shù) { alert(e); } } ) } });
The above is the entire content of this article. I hope it will be helpful to everyone in learning PHP programming.

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

TosettherighttimezoneinPHP,usedate_default_timezone_set()functionatthestartofyourscriptwithavalididentifiersuchas'America/New_York'.1.Usedate_default_timezone_set()beforeanydate/timefunctions.2.Alternatively,configurethephp.inifilebysettingdate.timez

ThePhpfunctionSerialize () andunserialize () AreusedtoconvertcomplexdaTastructdestoresintostoraSandaBackagain.1.Serialize () c OnvertsdatalikecarraysorobjectsraystringcontainingTypeandstructureinformation.2.unserialize () Reconstruct theoriginalatataprom

The key to writing clean and easy-to-maintain PHP code lies in clear naming, following standards, reasonable structure, making good use of comments and testability. 1. Use clear variables, functions and class names, such as $userData and calculateTotalPrice(); 2. Follow the PSR-12 standard unified code style; 3. Split the code structure according to responsibilities, and organize it using MVC or Laravel-style catalogs; 4. Avoid noodles-style code and split the logic into small functions with a single responsibility; 5. Add comments at key points and write interface documents to clarify parameters, return values ??and exceptions; 6. Improve testability, adopt dependency injection, reduce global state and static methods. These practices improve code quality, collaboration efficiency and post-maintenance ease.

Yes,youcanrunSQLqueriesusingPHP,andtheprocessinvolveschoosingadatabaseextension,connectingtothedatabase,executingqueriessafely,andclosingconnectionswhendone.Todothis,firstchoosebetweenMySQLiorPDO,withPDObeingmoreflexibleduetosupportingmultipledatabas

PHP page caching improves website performance by reducing server load and speeding up page loading. 1. Basic file cache avoids repeated generation of dynamic content by generating static HTML files and providing services during the validity period; 2. Enable OPcache to compile PHP scripts into bytecode and store them in memory, improving execution efficiency; 3. For dynamic pages with parameters, they should be cached separately according to URL parameters, and avoid cached user-specific content; 4. Lightweight cache libraries such as PHPFastCache can be used to simplify development and support multiple storage drivers. Combining these methods can effectively optimize the caching strategy of PHP projects.

ToquicklytestaPHPcodesnippet,useanonlinePHPsandboxlike3v4l.orgorPHPize.onlineforinstantexecutionwithoutsetup;runcodelocallywithPHPCLIbycreatinga.phpfileandexecutingitviatheterminal;optionallyusephp-rforone-liners;setupalocaldevelopmentenvironmentwith
