


PHP Ajax JS implements multiple image uploads, ajax multiple images_PHP tutorial
PHP 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("确认删除吗")){ $("#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', //用于文件上传的服务器端请求地址 secureuri: false, //是否需要安全协议,一般设置为false fileElementId: 'file0', //文件上传域的ID dataType: 'json', //返回值类型 一般设置为json success: function (data) //服务器成功响应处理函数 { 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)//服务器响应失败处理函数 { 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

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

AI Hentai Generator
Generate AI Hentai for free.

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

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

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

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

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

Validator can be created by adding the following two lines in the controller.
