Use JS for directory upload (equivalent to bulk upload) _javascript tips

Source: Internet
Author: User
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> test File Upload </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 ("File path error or no!!");
return false;
}
List all Files
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 ');
}
Loop recursively read folder files
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 ();
}
Upload
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 ')); There is no Chinese in the path
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 (' (completed) ');
UploadFile ();
}else{
if (Dotstr.length >) {dotstr = '. ';} else{dotstr + = '. ';}
$ (Thisnode). Find (' span '). Text (' (uploaded in ' + Dotstr + ') ');
}
}, 1000);
}
}
Call this function in the return page of the IFRAME to implement the loop upload, otherwise the dead loop
function Uploadfinish () {
$ (' #showArea div[uploadstate=wait] '). EQ (0). attr (' uploadstate ', ' OK ');
}
</script>
<style type= "Text/css" >
body,td,th {
font-family: "Microsoft Ya Hei", Tahoma, Helvetica, Arial, \5b8b\4f53, Sans-serif;
}
</style>
<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= "Start" 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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.