Created
January 3, 2018 02:35
-
-
Save ShawnSWu/8c6a37d2b275f12a6eb6fb26c03c9ec1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type='text/javascript'> | |
| function _id(e){return document.getElementById(e)} | |
| _id('myfile').onchange = function(){ | |
| var theFile = this.files; | |
| if(theFile.length === 1){ | |
| var uploader = new XMLHttpRequest(); | |
| var file = new FormData(); | |
| uploader.onreadystatechange = function(){ | |
| if(uploader.readyState ===4 && uploader.status === 200){ | |
| console.log(uploader.responseTeXt); | |
| } | |
| } | |
| uploader.open('POST','uploadfile.php',true); | |
| uploader.send(file); | |
| alert('上傳1個檔案成功'); | |
| }else{ | |
| var start = 0, | |
| setter, | |
| buff=true; | |
| setter = setInterval(function(){ | |
| if(buff === true){ | |
| buff = false; | |
| var uploader = new XMLHttpRequest(); | |
| var file = new FormData(); | |
| file.append('file',theFile[start]); | |
| uploader.onreadystatechange = function(){ | |
| if(uploader.readyState === 4 && uploader.status === 200){ | |
| console.log(uploader.responseTeXt); | |
| clearInterval(setter); | |
| } | |
| } | |
| alert('上傳'+theFile.length+'個檔案成功'); | |
| uploader.open('POST','uploadfile.php',true); | |
| uploader.send(file); | |
| } | |
| console.log('999'); | |
| },500); | |
| } | |
| window.location.reload(); | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment