淘宝卖家的上传产品多图片功能做的很强大,本文就分享下淘宝的单图片上传。代码很简单,引用jquery.wallform.js即可。
上传表单和预览图片区域$("body").on("change", ".photoimg", <br>
function() { <br>
var obj = $(this); <br>
var imageForm = obj.parents(".imageform"); <br>
var preview_img = imageForm.next(".preview_img"); <br>
var btn = imageForm.find(".up_btn"); <br>
<br>
imageForm.ajaxForm({ <br>
target: preview_img, <br>
beforeSubmit: function() { <br>
imageForm.next("div.preview_img").html(""); <br>
preview_img.hide(); <br>
btn.hide(); <br>
}, <br>
success: function() { <br>
preview_img.show(); <br>
btn.show(); <br>
}, <br>
error: function() { <br>
btn.show(); <br>
preview_img.hide(); <br>
} <br>
}).submit(); <br>
});
通过JS绑定change事件来提交单个图片上传表单$("body").on("change", ".photoimg", <br>
function() { <br>
var obj = $(this); <br>
var imageForm = obj.parents(".imageform"); <br>
var preview_img = imageForm.next(".preview_img"); <br>
var btn = imageForm.find(".up_btn"); <br>
<br>
imageForm.ajaxForm({ <br>
target: preview_img, <br>
beforeSubmit: function() { <br>
imageForm.next("div.preview_img").html(""); <br>
preview_img.hide(); <br>
btn.hide(); <br>
}, <br>
success: function() { <br>
preview_img.show(); <br>
btn.show(); <br>
}, <br>
error: function() { <br>
btn.show(); <br>
preview_img.hide(); <br>
} <br>
}).submit(); <br>
});
PHP后台处理上传图片if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") { <br>
$name = $_FILES['photoimg']['name']; <br>
$size = $_FILES['photoimg']['size']; <br>
<br>
if (empty($name)) { <br>
echo '请选择要上传的图片'; <br>
exit; <br>
} <br>
$ext = extend($name); <br>
if (!in_array($ext, $extArr)) { <br>
echo '图片格式错误!'; <br>
exit; <br>
} <br>
if ($size > (1000 * 1024)) { <br>
echo '图片大小不能超过1M'; <br>
exit; <br>
} <br>
$image_name = time() . rand(100, 999) . "." . $ext; <br>
$tmp = $_FILES['photoimg']['tmp_name']; <br>
if (move_uploaded_file($tmp, $path . $image_name)) { <br>
echo '<img class="preview lazy" src="/static/imghwm/default1.png" data-src="' . $path . $image_name . '" alt="jQuery仿淘宝无刷新上传产品图片" >'; <br>
} else { <br>
echo '上传出错了!'; <br>
} <br>
exit; <br>
}
PHP仿淘宝上传演示教程地址:http://www.sucaihuo.com/js/513.html
PHP+jQuery+Ajax仿淘宝多上传按钮单文件上传.rar
( 27.98 KB 下载:144 次 )
AD:真正免费,域名+虚机+企业邮箱=0元

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

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
