First, the picture can find the choice in the page. Design a form page
index.aspand upload Selection page
upload.asp, Upload.asp is included in the index.asp with an IFRAME.
Second, the selected picture should be able to be uploaded to a folder. Create a folder
uploadimg
last, how should the picture be quoted? Obviously, the UBB is displayed immediately. The Upload.asp object upfile.asp has the ability to write to the UBB tag.
No Component Upload Debug folder --Index.asp --Upload.asp --Upfile.asp --Uploadimg Folder
|
Pictures uploaded using the old farmer's no component upload. So upload.inc files are essential.
1,upload.inc (copy all code for the following text box)
<script runat=server language=vbscript> Dim upfile_5xsoft_stream Class Upload_5xsoft Dim Form,File,Version Pri Vate Sub Class_Initialize Dim istart,ifilenamestart,ifilenameend,iend,vbenter,iformstart,iformend,thefile Dim str Div,mformname,mformvalue,mfilename,mfilesize,mfilepath,idivlen,mstr version= "" If Request.TotalBytes<1 then Exi T Sub set Form=createobject ("Scripting.Dictionary") Set File=createobject ("Scripting.Dictionary") set Upfile_5 Xsoft_stream=createobject ("ADODB.stream") upfile_5xsoft_stream.mode=3 upfile_5xsoft_stream.type=1 upfile_5xSof T_stream.open upfile_5xsoft_stream.write Request.BinaryRead (request.totalbytes) vbEnter=Chr (10) Idivlen=instring (1,vbenter) +1 strdiv=substring (1,idivlen) Iformstart=idivlen iformend=instring (iformStart,s TRDIV)-1 while Iformstart < Iformend istart=instring (Iformstart, "name=" "") iend=instring (Istart+6, "" "") Mformname=substring (istart+6,iend-istart-6) ifilenamestart=instring (iend+1, "filename=" "") if Ifilenamestart>0 and iFileNameStart& Lt;iformend then ifilenameend=instring (ifilenamestart+10, "" "") mfilename=substring (Ifilenamestart+10,ifilenameen D-IFILENAMESTART-10) istart=instring (ifilenameend+1,vbenter&vbenter) iend=instring (IStart+4,vbEnter&strD IV) If Iend>istart then mfilesize=iend-istart-4 else mfilesize=0 End If set thefile=new FileInfo thefile.filename=getfilename (mfilename) Thefile.filepath=getfilepath (mfilename) thefile.filesize= Mfilesize thefile.filestart=istart+4 thefile.formname=formname File.add mformname,thefile else is Tart=instring (Iend+1,vbenter&vbenter) iend=instring (istart+4,vbenter&strdiv) if IEnd>iStart then Mformvalue=substring (istart+4,iend-istart-4) Else mformvalue= "" "End if form. ADD Mformname,mformvalue End If Iformstart=iformend+idivlen iformend=instring (Iformstart,strdiv)-1 Wend end Sub Private Function subString (Thestart,thelen) Dim i,c,stemp upfile_5xsoft_stream.position=thestart-1 stemp= "" for I=1 to TheLen if Upfile_5xsoft_ Stream.eos then Exit for C=ASCB (Upfile_5xsoft_stream.read (1)) if C > 127 then if Upfile_5xsoft_stream.eos then exit For STEMP=STEMP&CHR (AscW (ChrB AscB (Upfile_5xsoft_stream.read (1)) &CHRB (c)) i=i+1 else STEMP=STEMP&CHR (c) End If Next substring=stemp End Function Private function instring (thestart,varstr) Dim i,j,bt,thelen,str Instri Ng=0 str=tobyte (VARSTR) Thelen=lenb (STR) for I=thestart to Upfile_5xsoft_stream.size-thelen if I>upfile_5xsoft_stre Am.size then exit Function upfile_5xsoft_stream.position=i-1 if AscB (Upfile_5xsoft_stream.read (1)) =ASCB (MidB (str,1)) Then instring=i for j=2 to TheLen if Upfile_5xsoft_stream.eos then instring=0 Exit for End If if AscB (Upfile_ 5xsoft_stream.read (1)) <>aScB (MidB (str,j,1)) then instring=0 exit For End If Next if Instring<>0 then exit Function End If Next Function Private Sub class_terminate form. RemoveAll file. RemoveAll set form=nothing set file=nothing upfile_5xsoft_stream.close set upfile_5xsoft_stream=nothing end Sub P rivate function GetFilePath (fullpath) If fullpath <> "" Then GetFilePath = Left (Fullpath,instrrev (FullPath, "\")) Else GetFilePath = "" End If End Function Private function GetFileName (fullpath) if FullPath <> "" Then get FileName = Mid (Fullpath,instrrev (FullPath, "\") +1) Else GetFileName = "" End-If End Function Private function ToByte (str) Dim I,icode,c,ilow,ihigh tobyte= "for I=1 to Len (str) c=mid (str,i,1) Icode =asc (c) If icode<0 Then = Icode + 65535 If icode>255 Then Ilow = Left (Hex (ASC (c)), 2 Ihigh =right (Hex (ASC (c)), 2) ToByte = tobyte & Ch RB ("&h" &ilow) & ChrB ("&h" &ihigh) Else tobyte = tobyte & ChRB (AscB (c)) End If Next End Function End Class class FileInfo Dim Formname,filename,filepath,filesize,filestart Pri Vate Sub Class_Initialize FileName = "FilePath =" "FileSize = 0 filestart= 0 FormName =" "End Sub public fun Ction SaveAs (FullPath) Dim dr,errorchar,i Saveas=1 If Trim (fullpath) = "" or filesize=0 or filestart=0 or filename= "" " n Exit Function if filestart=0 or right (fullpath,1) = "/" Then Exit Function set Dr=createobject ("ADODB.stream") Dr. Mode=3 Dr. Type=1 Dr. Open upfile_5xsoft_stream.position=filestart-1 Upfile_5xsoft_stream.copyto Dr,filesize Dr. SaveToFile fullpath,2 Dr. Close Set dr=nothing saveas=0 End Function End Class </SCRIPT>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]
2, Form page
index.asp。 Note the Upload Selection page that the frame contains
upload.asp
<textarea class="bk" id="temp64850" rows="12"><form name= "Form_name" method= "POST" action= "add.asp" > <textarea "cols=" name= "Cn_content" rows= "18" Width= "100%" ></textarea> </form> <iframe border= "0" frameborder= "0" noresize scrolling= "no" width= " 100% "src=" upload.asp "></iframe></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]
3, Upload Selection page
upload.aspNote: enctype= "Multipart/form-data"
<textarea class="bk" id="temp42824" rows="12"><form name= "form" method= "POST" action= "upfile.asp" enctype= "Multipart/form-data" > <input type= "hidden" Name= "filepath" value= "uploadimg" > <input type= "hidden" name= "act" value= "upload" > <input type= "file" name = "File1" size=40> <input type= "Submit" Class=button Name= "submit" value= "Upload picture" onclick= "parent.document.forms[0 ]. Submit.disabled=true "> Type: gif,jpg, limited: 100K </form></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]
4, last file
upfile.aspMain function: Generate picture name, and upload the picture, also want to write the UBB tag to the index.asp in the textarea.
(Copy all the code for the following text box)
<!--#include file= "upload.inc"--> <ptml> <pead> <title> file upload </title> </pead> < Body> <script> Parent.document.forms[0]. Submit.disabled=false; </script> <% Dim upload,file,formname,formpath,icount,filename,fileext Set upload=new Upload_5xsoft ' Build upload Object Formpath=upload.form ("filepath") ' in the Directory Plus (/) if Right (formpath,1) <> "/" Then formpath=formpath& "/" Response.Write "<body>" icount=0 for every formName in Upload.file ' lists all uploaded files set file=upload.file (FormName) ' generated A file object if file.filesize<100 then Response.Write "Please select the file you want to upload [<a href=# onclick=history.go ( -1) > re-upload </a> ] "Response.End End If file.filesize>100*1000 then Response.Write" File size exceeded limit 100K [<a href=# onclick= History.go ( -1) > re-upload </a>] "Response.End End If Fileext=lcase (right (file.filename,4) Uploadsuc=false forum_ Upload= "Gif,jpg,png" Forumupload=split (Forum_upload, ",") for I=0 to UBound (forumupload) If fileext= "." &trim (Forumupload (i)) then uploadsuc=true exit for else Uploadsuc=false End If Next if uploadsuc=false the N Response.Write "file format is incorrect [<a href=# onclick=history.go ( -1) > re-upload </a>]" Response.End End If Randomize Rannum=int (90000*rnd) +10000 filename=formpath&year (now) &month (now) &day (now) &hour (now) & Minute (now) &second (now) &rannum&fileext if file. Filesize>0 Then ' if FileSize > 0 indicates that there are file data files. SaveAs server.mappath (filename) ' Saves the file for the i=0 to UBound (forumupload) if fileext= '. ' &trim (Forumupload (i)) then Response.Write "<script>parent.form_name.cn_content.value+= ' [img]" & filename& "[/img] ' </script>" Exit For End If Next icount=icount+1 End If set file=nothing next set U Pload=nothing ' Delete this object htmend icount& "File Upload end!" Sub Htmend (MSG) Set upload=nothing Response.Write "uploaded successfully [<a href=# onclick=history.go ( -1) > Continue uploading </a>]" resp Onse.end End SUB%> </body> </ptml>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]
Of course, keep the picture of the folder uploadimg not less