基于Ajaxupload的多文件上傳操作
廢話不多說(shuō)了,直接給大家貼代碼了,具體代碼如下所示:
<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><!-- 第一個(gè)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/><!-- 第二個(gè)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><!-- 第二個(gè)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>
總結(jié)
以上所述是小編給大家介紹的基于Ajaxupload的多文件上傳操作,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
AJAX如何接收J(rèn)SON數(shù)據(jù)示例介紹
如何使用AJAX返回JSON數(shù)據(jù),就是dataType,當(dāng)你設(shè)置json后返回的json字符串傳遞到客戶(hù)端就是JSON對(duì)象了,示例如下,感興趣的朋友可以參考下2013-08-08
jQuery AJAX實(shí)現(xiàn)調(diào)用頁(yè)面后臺(tái)方法
這篇文章主要為大家詳細(xì)介紹了jQuery AJAX實(shí)現(xiàn)調(diào)用頁(yè)面后臺(tái)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05
使用Yii整合的pjax(pushstate+ajax)實(shí)現(xiàn)無(wú)刷新加載頁(yè)面
本篇文章給大家介紹Yii整合pjax(pushstate+ajax)實(shí)現(xiàn)無(wú)刷新加載頁(yè)面,小伙伴跟著小編一起學(xué)習(xí)吧2015-09-09
AJax 把拿到的后臺(tái)數(shù)據(jù)在頁(yè)面中渲染的實(shí)例
今天小編就為大家分享一篇AJax 把拿到的后臺(tái)數(shù)據(jù)在頁(yè)面中渲染的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
Ajax跨域請(qǐng)求COOKIE無(wú)法帶上的完美解決辦法
這篇文章主要介紹了Ajax跨域請(qǐng)求COOKIE無(wú)法帶上的解決辦法,需要的朋友可以參考下2017-04-04
如何解決遠(yuǎn)程頁(yè)面抓取中的亂碼問(wèn)題
如何解決遠(yuǎn)程頁(yè)面抓取中的亂碼問(wèn)題...2006-12-12
基于ajax html實(shí)現(xiàn)文件上傳技巧總結(jié)
這篇文章主要為大家詳細(xì)總結(jié)了基于ajax html實(shí)現(xiàn)文件上傳技巧,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
Ajax異步請(qǐng)求技術(shù)實(shí)例講解
ajax是一種在無(wú)需重新加載整個(gè)網(wǎng)頁(yè)的情況下,能夠更新部分網(wǎng)頁(yè)的技術(shù)。下面通過(guò)本文給大家分享Ajax異步請(qǐng)求技術(shù)實(shí)例講解,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下吧2017-08-08

