您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Ajaxupload多文件上传

2026/1/27 15:45:32发布48次查看
这次给大家带来ajaxupload多文件上传,ajaxupload多文件上传的注意事项有哪些,下面就是实战案例,一起来看一下。
<pre name="code" class="php"><?php $ele = $_get['ele']; $file = $_files['thumb_'.$ele]; $pathinfo = pathinfo($file['name']); $filedir = 'uploads/' . date('y'); if (!is_dir($filedir)) { mkdir($filedir); } $filedir .= '/' . date('md'); if (!is_dir($filedir)) { mkdir($filedir); } $filedir .= '/' . time() . '_' . mt_rand(1000, 9999) . '.' . $pathinfo['extension']; $msg = ''; if (!move_uploaded_file($file['tmp_name'], $filedir)) { $msg = '上传失败'; } $data = array('msg' => $msg, 'filedir' => $filedir); sleep(2); echo json_encode($data); ?></pre><br> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="content-type" content="text/html; charset=gbk" /><title>ajax上传</title><script src="jquery-1.4.4.min.js" type="text/javascript"></script><script src="ajaxfileupload.js" type="text/javascript"></script><script type="text/javascript">function fileupload( ele ){$("#loading").ajaxstart(function() {jquery("#photoimg").hide();jquery(this).show();}).ajaxcomplete(function() {jquery(this).hide();jquery("#photoimg").show();});$.ajaxfileupload({url: "index.php?ele="+ele,secureuri: false,fileelementid: "thumb_"+ele,datatype: "json",success: function(data, status) {if(data.msg != '') {alert(data.msg);}else {$("[name='photo_"+ele+"']").val(data.filedir);$("#photoimg_"+ele).attr("src", data.filedir);}},error: function (data, status, e) {alert(e);}})return false;}</script></head><body><!-- 第一个ajax上传 --><input type="file" id="thumb_1" name="thumb_1" onchange="return fileupload('1');" /><p><img src="ajaxloading.gif" id="loading" style="display: none" /><img src="" id="photoimg_1" width="200px" height="150px" /><input type="text" name="photo_1" size=100/></p><hr/><!-- 第二个ajax上传 --><input type="file" id="thumb_2" name="thumb_2" onchange="return fileupload('2');" /><p><img src="ajaxloading.gif" id="loading" style="display: none" /><img src="" id="photoimg_2" width="200px" height="150px" /><input type="text" name="photo_2" size=100 /></p><!-- 第二个ajax上传 --><input type="file" id="thumb_2" name="thumb_2" onchange="return fileupload('2');" /><p><img src="ajaxloading.gif" id="loading" style="display: none" /><img src="" id="photoimg_2" width="200px" height="150px" /><input type="text" name="photo_2" size=100 /></p><a>添加</a></body></html> <pre></pre> <p><br> </p> <p><br> </p> <p><br> </p> <br>
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
以上就是ajaxupload多文件上传的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product