使用JS進(jìn)行目錄上傳(相當(dāng)于批量上傳)
<!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=gb2312" />
<title>測(cè)試文件上傳</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(function(){
//ShowFolderFileList("D:\\CodeNet\\web\\Images\\shopTemplets");
});
function ShowFolderFileList(FilePath){
var fso, f, fc, sf;
fso = new ActiveXObject("Scripting.FileSystemObject");
try{
f = fso.GetFolder(FilePath);
}catch(err){
alert("文件路徑錯(cuò)誤或者不存在!!");
return false;
}
// 列出所有文件
fc = new Enumerator(f.files);
var fileName = "";
for(;!fc.atEnd();fc.moveNext()){
fileName=fc.item().Name;
$('<div filePath="' + FilePath + fileName + '" uploadState="wait">' + FilePath + fileName + '</div>').appendTo('#showArea');
}
// 循環(huán) 遞歸 讀取 文件夾的文件
sf = new Enumerator(f.SubFolders);
var folderName = "";
for(;!sf.atEnd();sf.moveNext()){
folderName = sf.item().Name;
ShowFolderFileList(FilePath + folderName + "/");
}
}
function startUpload(){
var s = $('#uploaddir').val().replace( /\\/gi, '/' ) ;
if(s.substring(s.length - 1 , s.length) != '/'){
s += '/'
}
ShowFolderFileList(s)
uploadFile();
}
// 上傳
function uploadFile(){
if($('#showArea div[uploadState=wait]').length > 0){
var thisNode = $('#showArea div[uploadState=wait]').eq(0)
var WshShell=new ActiveXObject("WScript.Shell");
$('#fileupload').focus();
WshShell.SendKeys($(thisNode).attr('filePath')); // 路徑中不有是中文
uploadForm.submit();
$('#fileupload').focus();
$('#fileupload').get(0).createTextRange().select();
WshShell.SendKeys('{del}');
var dotStr = '.';
$('<span></span>').appendTo(thisNode).css('color', 'green');
var uploadState = setInterval(function(){
if($(thisNode).attr('uploadState') == 'ok'){
clearInterval(uploadState);
$(thisNode).find('span').css('color', 'red').text('(完成)');
uploadFile();
}else{
if(dotStr.length > 15){ dotStr = '.'; }else{ dotStr += '.'; }
$(thisNode).find('span').text('(上傳中' + dotStr + ')');
}
}, 1000);
}
}
// 在iframe 的返回頁面中調(diào)用此函數(shù) 即可實(shí)現(xiàn)循環(huán)上傳,,否則為死循環(huán)
function uploadFinish(){
$('#showArea div[uploadState=wait]').eq(0).attr('uploadState', 'ok');
}
</script>
<style type="text/css">
body,td,th {
font-family: "微軟雅黑", Tahoma, Helvetica, Arial, \5b8b\4f53, sans-serif;
}
</style>
</head>
<body>
<form action="/a.html" method="post" name="loginForm" style="margin:0 0; padding:0 0;">
<input name="uploaddir" id="uploaddir" type="text" value="D:\a" style="width:800px;" />
<input type="button" value="開始" id="startIt" name="startIt" onclick="javascript:startUpload();"/>
</form>
<form action="/index/upload" method="post" name="uploadForm" enctype="multipart/form-data" target="hidden_frame">
<input type="file" name="fileupload" id="fileupload" />
<iframe name='hidden_frame' id="hidden_frame" style='display:none'></iframe>
</form>
</iframe>
<div id="showArea">
</div>
</body>
</html>
相關(guān)文章
JS關(guān)鍵字球狀旋轉(zhuǎn)效果的實(shí)例代碼
這篇文章主要介紹了JS關(guān)鍵字球狀旋轉(zhuǎn)效果的實(shí)例代碼。需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-11-11select標(biāo)簽設(shè)置默認(rèn)選中的選項(xiàng)方法
下面小編就為大家分享一篇select標(biāo)簽設(shè)置默認(rèn)選中的選項(xiàng)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03JavaScript Array Flatten 與遞歸使用介紹
用 JavaScript 將 [1,2,3,[4,5, [6,7]], [[[8]]]] 這樣一個(gè) Array 變成 [1,2,3,4,5, 6,7,8] 呢?傳說中的 Array Flatten2011-10-10js菜單點(diǎn)擊顯示或隱藏效果的簡(jiǎn)單實(shí)例
本篇文章主要是對(duì)js菜單點(diǎn)擊顯示或隱藏效果的簡(jiǎn)單實(shí)例進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2014-01-01微信小程序動(dòng)態(tài)設(shè)置導(dǎo)航欄標(biāo)題的實(shí)現(xiàn)步驟
實(shí)際開發(fā)中很多時(shí)候我們需要通過上個(gè)頁面?zhèn)鬟^來的值動(dòng)態(tài)的更改標(biāo)題欄文字,下面這篇文章主要給大家介紹了關(guān)于微信小程序動(dòng)態(tài)設(shè)置導(dǎo)航欄標(biāo)題的實(shí)現(xiàn)步驟,需要的朋友可以參考下2023-02-02javascript實(shí)例--教你實(shí)現(xiàn)撲克牌洗牌功能
我們一般都會(huì)按照順序把隨機(jī)摸過來的牌從小到大的順序在手上理整齊(記得小時(shí)候打牌兩副牌手都抓不過來),這篇隨筆就是想通過實(shí)現(xiàn)這個(gè)功能來熟悉下js中排序數(shù)組等相關(guān)知識(shí)。2014-05-05JS實(shí)現(xiàn)簡(jiǎn)單面向?qū)ο蟮念伾x擇器實(shí)例
這篇文章主要介紹了JS實(shí)現(xiàn)簡(jiǎn)單面向?qū)ο蟮念伾x擇器,以完整實(shí)例形式分析了JavaScript基于面向?qū)ο髮?shí)現(xiàn)顏色選擇器的具體步驟與實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-04-04JavaScript用select實(shí)現(xiàn)日期控件
這篇文章主要介紹了JavaScript用select實(shí)現(xiàn)日期控件的相關(guān)資料,需要的朋友可以參考下2015-07-07