Upload | samples | No components The following code has no specifications, and some features are not completed, there is the master can modify it, packaged into a class is more for the benefit of the public, or later I will do the time. There are any mistakes or suggestions please make sure to send me e-mail:sobina@21cn.com, thank you.
Okay, less to say more, this example tests through in W2kserver,iis5,sql SERVER7.
If you do not understand can go to the essence of the "image" or "picture" keyword to find the answer, or write to me.
Example a total of three files: upload.htm (Upload interface)
process.asp (processing program)
Showimg.asp (show image)
Database: Create a new table named Imgtest in the pubs database
Field Name Type length
----------------------------------------------
ID Int (autonumber)
IMG Iamge
Imginfo NCHAR 50
The following are the code for three files:
Upload.htm
---------------------------------------------------------------------
<title>untitled document</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style type= "Text/css" >
<!--
td {FONT-SIZE:9PT}
A {color: #000000; Text-decoration:none}
a:hover {Text-decoration:underline}
. tx {height:16px; width:30px; border-color:black black #000000; border-top-width:0px;
border-right-width:0px; border-bottom-width:1px; border-left-width:0px; font-size:9pt;
Background-color: #eeeeee; Color: #0000FF}
. bt {font-size:9pt; border-top-width:0px; border-right-width:0px; border-bottom-width:0px;
border-left-width:0px; height:16px; width:80px; Background-color: #eeeeee; Cursor:hand}
. tx1 {height:20px; width:30px; font-size:9pt; border:1px solid; Border-color:black Black
#000000; Color: #0000FF}
-->
</style>
<body bgcolor= "#FFFFFF" text= "#000000" >
<form name= "Form1" method= "Post" action= "process.asp" enctype= "Multipart/form-data" >
<table width= "71%" border= "1" cellspacing= "0" cellpadding= "5" align= "center"
bordercolordark= "#CCCCCC" bordercolorlight= "#000000" >
<tr bgcolor= "#CCCCCC" >
<TD height= "align=" "left" valign= "Middle" bgcolor= "#CCCCCC" > Sobina
Graphics and text upload interface </td>
</tr>
<tr align= "left" valign= "Middle" bgcolor= "#eeeeee" >
<TD bgcolor= "#eeeeee" > <br>
</td>
</tr>
<TR align= "center" valign= "Middle" >
<TD align= "left" id= "Upid" height= "122" >
<p> Image path:
<input type= "file" Name= "img" style= "width:400" class= "tx1" "value=" ">
</p>
<p> image description:
<input type= "text" name= "Imginfo" >
</p>
</td>
</tr>
<TR align= "center" valign= "Middle" bgcolor= "#eeeeee" >
<TD bgcolor= "#eeeeee" height= "2" >
<input type= "Submit" name= "submit" value= "· Submit • "class=" BT ">
<input type= "reset" name= "Submit2" value= "· Reset • "class=" BT ">
</td>
</tr>
</table>
</form>
</body>
------------------------------------------------------------------------
Process.asp
------------------------------------------------------------------------
<!--#include file= ". /bin/strcnn.asp "-->
<%
Response.expires=0
' Purpose: Converts binary characters to normal characters
Function Bin2str (BINSTR)
Dim Varlen,clow,ccc,skipflag
Skipflag=0
CCC = ""
Varlen=lenb (BINSTR)
For I=1 to Varlen
If skipflag=0 Then
Clow = MidB (binstr,i,1)
If AscB (Clow) > 127 Then
CCC =CCC & Chr (AscW (MidB (binstr,i+1,1) & Clow))
Skipflag=1
Else
CCC = CCC & Chr (AscB (Clow))
End If
Else
Skipflag=0
End If
Next
BIN2STR = CCC
End Function
' Objective: To separate the image data from the form
' Where the parameter formsize is the form data size, Formdata is the total data for the form
Function Imageup (Formsize,formdata)
BNCRLF=CHRB (+) & ChrB (10)
Divider=leftb (FORMDATA,INSTRB (FORMDATA,BNCRLF)-1) ' Formdata the data on the left of the first Bncrlf
DATASTART=INSTRB (Formdata,bncrlf & Bncrlf) +4 ' two Bncrlf the starting bit of the right data
DATAEND=INSTRB (Datastart+1,formdata,divider)-datastart
IMAGEUP=MIDB (Formdata,datastart,dataend)
End Function
' Purpose: To remove the value of a variable from a form
' Where the parameter varname is the field variable to look for, strtxt all text that has been detached from the image
Function Findvar (Varname,strtxt)
Startpos=1
Strlen=len (VarName) +2
' There may be multiple variables with the same name in the form (used in the data update with the main table and the BOM)
For I=1 to Len (strtxt