基于Ajaxupload的多文件上传操作
网络编程 2021-07-05 10:37www.168986.cn编程入门
本文通过实例代码给大家介绍了基于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://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://.w3./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",suess: 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');" /><div><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/></div><hr/><!-- 第二个ajax上传 --><input type="file" id="thumb_2" name="thumb_2" onchange="return fileupload('2');" /><div><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 /></div><!-- 第二个ajax上传 --><input type="file" id="thumb_2" name="thumb_2" onchange="return fileupload('2');" /><div><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 /></div><a>添加</a></body></html> <pre></pre> <p><br> </p> <p><br> </p> <p><br> </p> <br>
以上所述是长沙网络推广给大家介绍的基于Ajaxupload的多文件上传操作,希望对大家有所帮助,如果大家有任何疑问请给我留言,长沙网络推广会及时回复大家的。在此也非常感谢大家对狼蚁SEO网站的支持!
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指