Kode Prinsip:
strfilename = request.queryString ("file1") Set ObjStream = Server.CreateObject ("AdodB.Stream") objstream.type = 1 'adtypeBinary objstream.open Objstream.LoadFromFile Strfilename objstream.savetofile server.mappath ("123_onweb.gif"), 2 |
Bagaimana menggunakan:
Tulis kode di atas sebagai unggah.asp
Memasuki:
http: //xxx/upload.asp? file1 = c:/unggah file/123.gif
Xxx adalah alamat host Anda
Setelah eksekusi, Anda akan melihat bahwa ada tambahan 123_onweb.gif di direktori Anda
Dia adalah apa yang Anda inginkan
Menurut prinsip kami dapat memperpanjang kode berikut:
unggah.htm file
<Form name = "Form" Action = "unggah.asp" Metode = "POST"> <input type = "file" name = "file1" value = ""> <input type = "kirim" name = "kirim" value = "ok"> </form> |
unggah.asp file
<% Fungsi getFileName (Byval Strfile) Jika strfile <> "" lalu GetFileName = mid (strfile, instrrev (strfile, "/")+1) Kalau tidak GetFileName = "" Akhiri jika Fungsi akhir strfilename = request.form ("file1") Set ObjStream = Server.CreateObject ("AdodB.Stream") objstream.type = 1 'adtypeBinary objstream.open Objstream.LoadFromFile Strfilename objstream.savetofile server.mappath (getFileName (strfileName)), 2 objstream.close %> |
Debugging lokal berhasil, tetapi mode C/S tidak lewat!