À̹ø¿¡´Â ÆÄÀϾ÷·Îµå¿Í ´õºí¾î¼¸® ÆÄÀÏ¿¡ ´ëÇÑ Á¤º¸¸¦ DB¸¦ ÀÌ¿ëÇÏ¿© ÀúÀåÇÏ´Â ¹æ¹ýÀ» ¾Ë¾Æº¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
ÆíÀÇ»ó Access ÆÄÀÏÀ» DB·Î ÀÌ¿ëÇÏ°Ú½À´Ï´Ù. º¸Åë ÀÌ ¾÷·Îµå´Â ÀÚ·á½ÇÀ» ¸¸µé¶§ ÁÖ·Î »ç¿ëÇÏ°Ô µÇ´Âµ¥ ¿äÁòÀº
ÀÚ·á½ÇÀ̶ó°í µû·Î ¸¸µå´Â°Ô ¾Æ´Ï¶ó °Ô½ÃÆÇ¿¡ ±×³É ÆÄÀÏ ¾÷·Îµå ±â´ÉÀ» Ãß°¡ÀûÀ¸·Î ºÙ¿© »ç¿ëÇÏ°í ÀÖÁÒ.
±×·¡¼ º¸Åë °Ô½ÃÆǸ¸µé±â¿¡¼ ÀÚ·á¾÷·Îµå ¹æ¹ýÀ» ¸¹ÀÌ ¼³¸íÇϴµ¥ º¸Åë °Ô½ÃÆǸ¸µé±â ¼³¸í¿¡ ÆÄÀϾ÷·Îµå ±â´É ºÎºÐÀ»
°°ÀÌ ¼³¸íÇÏ¸é º¹ÀâÇØ Áú ¼ö°¡ ÀÖ¾î¼ µû·Î ÆÄÀÏ ¾÷·Îµå ÇÏ´Â ºÎºÐ¸¸ ÀÌ·¸°Ô ÀÚ¸®¸¦ ¸¶·ÃÇÏ¿´½À´Ï´Ù.
ÀÌ°÷¿¡¼´Â ÆÄÀÏÀ» ¾÷·ÎµåÇÏ°í À̶§ ÆÄÀÏ¿¡ ´ëÇÑ Á¤º¸¸¦ DB¾È¿¡ ÀúÀåÇÏ´Â °£´ÜÇÑ ¹æ¹ýÀ» ¾Ë¾Æº¸°Ú½À´Ï´Ù. ±×·¡¼
DB¾È¿¡ ÀúÀåÇÒ ³»¿ëÀº ´ÙÀ½°ú °°ÀÌ 3°¡Áö¸¸ ÇÏ°Ú½À´Ï´Ù.
¨ç ÆÄÀÏÀ̸§ : ¾÷·ÎµåÇÑ ÆÄÀÏÀÇ À̸§°ú È®Àå¸í ÀúÀå
¨è ÆÄÀÏ°æ·Î : ¾÷·ÎµåÇÑ ÆÄÀÏÀÇ »ó´ëÀû °æ·Î¸í ÀúÀå
¨é ÆÄÀÏÅ©±â : ¾÷·ÎµåÇÑ ÆÄÀÏÀÇ Å©±âÀúÀå
ÀÚ, ÀÌÁ¦ ¸¸µé¾î º¾½Ã´Ù. óÀ½¿¡ ¸»ÇßµíÀÌ DB´Â Access¸¦ ÀÌ¿ëÇÏ°Ú½À´Ï´Ù. ±×·³ ´ÙÀ½±×¸²°ú °°ÀÌ°¢°¢ÀÇ
Çʵå¸íÀ» °¡Áø DB¸¦ ¸¸µé¾îº¾½Ã´Ù.
ÆíÀÇ»ó DB´Â C:\DataStore Æú´õ¿¡ db.mdb À̶ó ÇÏ°í Å×À̺í À̸§Àº tb_upload ¶ó ÇÏ°Ú½À´Ï´Ù.
¿©±â¼ ¼³¸íÇÒ ºÎºÐÀº »ç¿ëÀÚ¿¡°Ô ÆÄÀÏÀ» ¿Ã¸± ¼ö ÀÖµµ·Ï ÇÏ´Â ¹®¼(dbupload.html)¿Í ½ÇÁ¦·Î ÆÄÀÏÀ»
¿Ã¸®´Â ¹®¼(dbupload.asp)¸¦ ÀÛ¼ºÇϵµ·Ï ÇÏ°Ú½À´Ï´Ù. ±×¸®°í ¾÷·ÎµåÇÑ ÆÄÀÏÀ» ÀúÀåÇÒ Æú´õ´Â dbupload.html,dbupload.asp
¹®¼°¡ ÀÖ´Â Æú´õÀÇ ÇÏÀ§ Æú´õ·Î dirupload Æú´õ¿¡ ÀúÀåÇÏ°Ú½À´Ï´Ù. ±×¸®°í ÀúÀåµÈ ÆÄÀÏ°ú DB¾È¿¡ ÀÖ´Â
ÆÄÀÏÁ¤º¸¸¦ Ãâ·Â½ÃÅ°´Â ¹®¼¸¦ ¸¸µé¾î º¾½Ã´Ù. 1.
dbupload.html ¹®¼ ¸¸µé±â
<html> <body> <form
method="post" action="dbupload.asp"
enctype="multipart/form-data">
<input type="file" name="file"><br>
<input type="submit" name="submit" value="submit">
</form> <body> </html> |
2. dbupload.asp ¹®¼ ¸¸µé±â
<!--METADATA TYPE= "typelib" NAME=
"ADODB Type Library" FILE="C:\Program
Files\Common Files\SYSTEM\ADO\msado15.dll" -->
<%
Set theForm = Server.CreateObject("ABCUpload4.XForm")
Set theField = theForm("file")(1)
If theField.FileExists Then filename
= theField.SafeFileName filepath
= "./dirupload/" & theField.SafeFileName filesize
= theField.Length theField.Save
filepath Set cn = Server.CreateObject("ADODB.Connection")
strConnect="Provider=Microsoft.Jet.OLEDB.4.0;"
& _
"Data Source=C:\DataStore\updb.mdb" cn.Open
strConnect Set rs =
Server.CreateObject("ADODB.Recordset") rs.Open
"tb_upload",strConnect, adOpenStatic, adLockPessimistic,
adCmdTable rs.AddNew
rs.Fields("b_filename") = filename
rs.Fields("b_filepath") =
filepath rs.Fields("b_filesize")
= filesize rs.Update
rs.Close
End If
%> <html> <body>
File uploaded... </body> </html> |
3. dbupload.asp ¹®¼ ¼³¸í
<!--METADATA TYPE= "typelib" NAME=
"ADODB Type Library" FILE="C:\Program
Files\Common Files\SYSTEM\ADO\msado15.dll" -->
|
ADO »ó¼ö¸¦ ÀÌ¿ëÇϱâ À§ÇØ msado15.dll ÆÄÀÏÀ» À§¿Í°°ÀÌ ¿¬°á½ÃÄÑÁÝ´Ï´Ù. ADO »ó¼ö´Â ¾Æ·¡ºÎºÐ¿¡¼
·¹ÄÚµå¼Â °³Ã¼¸¦ ¿ÀÇÂÇÒ¶§ adOpenStatic, adLockPessimistic, adCmdTable »ó¼ö¸¦
ÀÌ¿ëÇÏ°Ô µË´Ï´Ù. ÀÌ »ó¼ö°¡ Á¤ÀÇ µÇ¾î ÀÖ´Â ÆÄÀÏÀÌ msado15.dll ÆÄÀÏÀÔ´Ï´Ù.
Set theForm = Server.CreateObject("ABCUpload4.XForm")
Set theField = theForm("file")(1) |
ABCUpload ÄÄÆ÷³ÍÆ®ÀÇ °³Ã¼ XFormÀÇ ÀνºÅϽº°ªÀ» »ý¼ºÇÏ´Â °úÁ¤°ú ÀÌ°ÍÀ» ÀÌ¿ëÇÏ¿© ¾÷·Îµå½ÃŲ ÆÄÀÏ¿¡
´ëÇÑ XField °³Ã¼ÀÇ ÀνºÅϽº°ªÀ» »ý¼ºÇÏ´Â ºÎºÐÀÔ´Ï´Ù. ÀÌÈÄ º¯¼ö theForm°ú theField´Â ÀÌ
µÎ°³ÀÇ °³Ã¼¸¦ ´ë½ÅÇÏ°Ô µË´Ï´Ù.
If theField.FileExists Then |
XField°³Ã¼ÀÇ FileExists ¼Ó¼ºÀ» °Ë»çÇؼ ¾÷·ÎµåÇÒ ÆÄÀÏÀÌ ÀÖÀ¸¸é ¾÷·Îµå°úÁ¤À¸·Î ³Ñ¾î°¡°Ô ÇÏ´Â Á¶°Ç¹®ÀÇ
»ç¿ëÀÔ´Ï´Ù.
filename = theField.SafeFileName
filepath = "./dirupload/" & theField.SafeFileName
filesize = theField.Length |
¿ª½Ã XField °³Ã¼ÀÇ ¼Ó¼º°ªÀ» ÀÌ¿ëÇϴµ¥ ¼Ó¼º SafeFileNameÀº ÆÄÀÏÀÇ À̸§ÀÇ °ªÀ» °¡Áö°í ÀÖ°í
ÀÌ°ÍÀ» º¯¼ö filename¿¡ ´ëÀÔÇÏ¿´½À´Ï´Ù. ±×¸®°í filepath´Â ¾÷·ÎµåÇÒ ÆÄÀÏÀÇ °æ·Î¸íÀ» filepath¶ó´Â
º¯¼ö¿¡ ³Ö¾ú½À´Ï´Ù. óÀ½¿¡ ¸»ÇßµíÀÌ dbupload.asp ¹®¼°¡ ÀÖ´Â Æú´õÀÇ ÇÏÀ§ Æú´õ dirupload·Î
ÆÄÀÏÀ̸§ ±×´ë·Î ÀúÀåÇϱâ À§ÇÏ¿© filepath¶ó´Â º¯¼ö¿¡ ÀúÀåÇÕ´Ï´Ù. ¼Ó¼º Length´Â ÆÄÀÏÀÇ Å©±â°ªÀ»
°¡Áö°Ô µË´Ï´Ù. ÀÌ°ÍÀ» filesize¶ó´Â º¯¼ö¿¡ ³Ö¾ú½À´Ï´Ù.
XField °³Ã¼¿¡¼ Áö¿øÇÏ´Â Save ¸Þ½îµå ÀÔ´Ï´Ù. Çü½ÄÀº theField.Save ÀúÀå°æ·Î¸í Àε¥ ¿©±â¼´Â
ÀÌÀü¿¡ filepath¶ó´Â º¯¼ö¿¡ ÆÄÀÏÀÇ »ó´ëÀû °æ·Î¸í(Æú´õÀÇÀ§Ä¡¿Í ÆÄÀÏÀ̸§)¸¦ ÁöÁ¤ÇßÀ¸¹Ç·Î ÀÌ º¯¼ö¸¦ path·Î
»ç¿ëÇÏ¿´½À´Ï´Ù. ÀÌ°ÍÀ¸·Î ÆÄÀÏ ¾÷·Îµå´Â ³¡ÀÔ´Ï´Ù.
Set cn = Server.CreateObject("ADODB.Connection")
strConnect="Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\DataStore\updb.mdb"
cn.Open strConnect |
ADO °³Ã¼ ConnectionÀÇ ÀνºÅϽº °ªÀ» »ý¼ºÇÏ°í ÀÌ°ÍÀ» ÀÌ¿ëÇÏ¿© DB¿¡ ¿¬°áÇϱâ À§ÇÑ Äõ¸®ÄÁ³Ø¼ÇÀÇ
°ªÀ» ÁöÁ¤ÇÏ°í ¿¬°áÇÏ´Â ¹æ¹ýÀÔ´Ï´Ù. ÀÌ·¸°Ô ÇÔÀ¸·Î½á ¿øÇÏ´Â DB·ÎÀÇ ¿¬°áÀÌ °¡´ÉÇÏ°Ô ÇÕ´Ï´Ù.
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "tb_upload",strConnect, adOpenStatic, adLockPessimistic,
adCmdTable |
ADO °³Ã¼ ·¹ÄÚµå¼Â °³Ã¼ÀÇ ÀνºÅϽº°ªÀ» »ý¼ºÇÏ°í ÀÌ°ÍÀ» ÀÌ¿ëÇÏ¿© Å×À̺í tb_board¿¡ ÀÖ´Â ·¹ÄÚµå¼ÂÀ»
ADO °³Ã¼ÀÇ ·¹ÄÚµå¼Â °³Ã¼·Î °¡Á®¿À´Â °úÁ¤À» ¼öÇàÇÏ°Ô µË´Ï´Ù. ¸Ç »ó´Ü¿¡ Æ÷ÇÔÇÑ ÆÄÀÏ¿¡¼ ÁöÁ¤ÇÑ »ó¼ö¸¦ ÀÌ¿ëÇÏ¿©
·¹ÄÚµå¼ÂÀ» ºÒ·¯¿Ã¶§ÀÇ Ä¿¼Å¸ÀÔ°ú ¶ôŸÀÔÀ» ÁöÁ¤ÇÏ´Â °úÁ¤ÀÔ´Ï´Ù. ¿©±â¼ »ç¿ëÇÑ ¹æ¹ýÀº ½ºÅ©·Ñ °¡´ÉÇÑ Ä¿¼Å¸ÀÔ°ú
¶ôÆÛ½º¹Ì½ºÆ½ ¹æ¹ýÀ» ÀÌ¿ëÇÏ¿´½À´Ï´Ù.
rs.AddNew
rs.Fields("b_filename") = filename
rs.Fields("b_filepath") = filepath
rs.Fields("b_filesize") = filesize
rs.Update
rs.Close |
»ý¼ºµÈ ·¹ÄÚµå¼ÂÀÇ ÀνºÅϽº°ªÀ» °¡Áø º¯¼ö rs¸¦ ÀÌ¿ëÇÏ¿© »õ·Î¿î ·¹Äڵ带 »ý¼ºÇÏ°í °¢°¢ÀÇ Çʵ忡 À§¿¡¼ ÁöÁ¤Çß´ø
º¯¼öÀÇ °ªÀ» Â÷·Ê·Î ´ëÀÔÇÏ°í ¾÷µ¥ÀÌÆ® ½ÃÅ°´Â °úÁ¤ÀÔ´Ï´Ù. ±×¸®°í ¾÷µ¥ÀÌÆ®°¡ ³¡³ª¸é ·¹ÄÚµå¼ÂÀ» ´Ý¾Æ¹ö¸®°í ÀÖ½À´Ï´Ù.
ÀÌ °úÁ¤ÀÌ ³¡³ª¸é ¿ì¸®°¡ »ç¿ëÇÏ´Â DB¾È¿¡ ÆÄÀÏ¿¡ ´ëÇÑ Á¤º¸°¡ ÀúÀåµÇ°Ô µË´Ï´Ù.
4. È®ÀÎ
¸ÕÀú ºê¶ó¿ìÀú·Î dbupload.html ¹®¼¸¦ ·ÎµùÇÑÈÄ Àû´çÇÑ ÆÄÀÏÀ» ¼±ÅÃÇÏ¿© ÆÄÀÏ Çϳª¸¦
¿Ã·Áº¸µµ·Ï ÇÏÀÚ ±×¸®°í ÆÄÀÏ ¾÷·ÎµùÀÌ ¹«»çÇÏ°Ô ³¡³µÀ¸¸é ÆÄÀÏ ¾÷·Îµå Á¤º¸¸¦ ´ã°í ÀÖ´Â DB¸¦ ¿¾î¼ ¾î¶² Á¤º¸°¡
ÀúÀåµÇ¾ú´ÂÁö È®ÀÎÇغ¸±â ¹Ù¶õ´Ù. ´ÙÀ½ ±×¸²Àº ÀÓÀÇÀÇ ÆÄÀÏÀ» ¾÷·ÎµùÇÑÈÄ DB¾È¿¡ ÀúÀåµÈ ÆÄÀÏ Á¤º¸ÀÌ´Ù.
5. DB¾ÈÀÇ Á¤º¸¸¦ Ãâ·Â½ÃÅ°±â - dbuploadview.asp
¹®¼
<!--METADATA TYPE= "typelib" NAME=
"ADODB Type Library" FILE="C:\Program
Files\Common Files\SYSTEM\ADO\msado15.dll" -->
<%
strConnect="Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\DataStore\updb.mdb"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnect
SQL = "SELECT * FROM tb_upload"
Set objRS = objConn.Execute(SQL)
Do while Not objRS.EOF filename
= objRS("b_filename") filepath
= objRS("b_filepath") filesize
= objRS("b_filesize") Response.Write
"ÆÄÀÏÀ̸§ : " & filename & _
" (" & filesize & ")" & _
" <a href=" & filepath & ">" & filename & "</a><br>"
objRS.MoveNext
Loop
Set objRS = nothing
Set objConn = nothing
%> |
¼Ò½ºÀÔ·ÂÈÄ È®ÀΠȸéÀº ´ÙÀ½°ú °°½À´Ï´Ù.
|
|