文件上傳一直很不方便,根據網站現有的文章,大多數是從客戶端取的數據,進行分解,取的文章的各種信息,我試著從另一種角度進行考慮:客戶端取的文件信息,然后上傳,例代碼如下:
<html> <script languge="javascript" type="text/javascript"> function oncleck() { filename=document.getElementById("file01").value if (filename=="") alert("輸入要上傳的文件") else { var filetype=new String(filename); var i; i=filetype.length; filetype=filetype.substring(i-4,i); var theform ; theform=document.getElementById("form01"); theform.action="savefile.asp?filetype="+filetype; return true; } return false; } function checkfile() { if (parent.window.document.getElementById("filename").value!="") { alert("文件已經上傳!") return false; } } </script> <body topmargin="0" bgcolor="#EDF1F1" leftmargin="0"> <form id=form01 method=post enctype="multipart/form-data" onsubmit="return oncleck()"> <input type=file name=file01 size=20 id=file01 onclick='checkfile()'><input type=submit value=上傳> </form> </body> </html> asp服務端代碼如下: <% '獲取文件后綴名 '------------------------------------------- filetype=request("filetype") %>
這樣便獲得文件后綴名,如果你會變通的話,還可以加以組合,獲得更多文件信息,例如:文件名等, 注意:關鍵理解為什么可以
|