รหัสหลัก:
strfilename = request.QueryString ("file1") ตั้งค่า objstream = server.createObject ("adodb.stream")) objstream.type = 1 'adtypebinary objstream.open objstream.loadfromfile strfilename objstream.savetofile Server.mappath ("123_onweb.gif"), 2 |
วิธีใช้:
เขียนรหัสด้านบนเป็น upload.asp
เข้า:
http: //xxx/upload.asp? file1 = c:/อัปโหลดไฟล์/123.gif
xxx เป็นที่อยู่โฮสต์ของคุณ
หลังจากดำเนินการแล้วคุณจะเห็นว่ามีอีก 123_onweb.gif ในไดเรกทอรีของคุณ
เขาคือสิ่งที่คุณต้องการไฟล์
ตามหลักการที่เราสามารถขยายรหัสต่อไปนี้:
upload.htm ไฟล์
<form name = "form" action = "upload.asp" method = "post"> <input type = "file" name = "file1" value = ""> <อินพุต type = "ส่ง" name = "submit" value = "ตกลง"> </form> |
upload.asp ไฟล์
- ฟังก์ชั่น getFilename (byval strfile) ถ้า strfile <> "" แล้ว getFilename = mid (strfile, instrrev (strfile, "/")+1) อื่น getFileName = "" สิ้นสุดถ้า ฟังก์ชันสิ้นสุด strfilename = request.form ("file1") ตั้งค่า objstream = server.createObject ("adodb.stream")) objstream.type = 1 'adtypebinary objstream.open objstream.loadfromfile strfilename objstream.savetofile Server.Mappath (getFilename (strfilename)), 2 objstream.close - |
การดีบักในท้องถิ่นนั้นประสบความสำเร็จ แต่โหมด C/S ไม่ผ่าน!