ClassicASP DextUpload 파일첨부 표준 글수정
페이지 정보
본문
첨부파일을 수정하는 샘플입니다.
##### edit.asp #####
<%@Language=VBScript%>
<%
response.expires = 0
uid = Request("uid")
set db = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
%>
<!--#include virtual="/dbConn.asp" -->
<%
sql = "select * from 테이블이름 where idx='" & idx &"' "
'response.write "sql = "&sql&"<br>"
rs.open sql,db,1
if not rs.eof then
idx = rs("idx")
name1 = rs("name1")
name2 = rs("name2")
imagename1 = rs("imagename1")
imagename2 = rs("imagename2")
else
Response.Write("<script>")
Response.Write("window.alert('해당 자료를 찾을 수 없습니다.');")
Response.Write("history.go(-1);")
Response.Write("</script>")
Response.End
end if
rs.close
'db.close
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.0 Transitional//EN" >
<html>
<head>
<title>업로드</title>
<script language="javascript">
<!--
function sendForm(){
document.fForm.submit()
}
//-->
</script>
</head>
<body>
<form name="fForm" method="post" action="edit_ok.asp" ENCTYPE="multipart/form-data">
<input type="hidden" name="uid" value="<%=uid%>">
<table width="600" border="0" cellpadding="0" cellspacing="1" bgcolor="#666666">
<tr>
<td width="80">항목</td>
<td><input name="name1" type="text" value="<%=name1%>"></td>
</tr>
<tr>
<td>파일 1</td>
<td><input NAME="file1" id="file1" type="file" />
<% if Len(imagename1) > 0 then %><br /><input type='checkbox' value='y' name='delcheck1' id='delcheck1' /><%=imagename1%><% end if %></td>
</tr>
<tr>
<td>파일 2</td>
<td><input NAME="file2" id="file2" type="file" />
<% if Len(imagename2) > 0 then %><br /><input type='checkbox' value='y' name='delcheck2' id='delcheck2' /><%=imagename2%><% end if %></td>
</tr>
<tr>
<td colspan="2" align="center"><input id="Button2" type="button" value="수정" onClick="javascript:sendForm();" /></td>
</tr>
</table>
</form>
</body>
</html>
##### edit_ok.asp #####
<%@Language=VBScript%>
<%
response.expires = 0
Set up_form = Server.CreateObject("DEXT.FileUpload")
up_form.UploadTimeout = 3600
up_form.DefaultPath = Server.MapPath(".\upload\") & "\"
FilePath = up_form.Save()
idx = up_form("idx")
name1 = up_form("name1")
name2 = up_form("name2")
delcheck1 = up_form("delcheck1")
delcheck2 = up_form("delcheck2")
dim fc, storedir, fexist
set fc = CreateObject("Scripting.FileSystemObject")
storedir=server.mappath(".\upload\")+"\"
'Response.Write "storedir = " & storedir & "<br>"
%>
<!--#include file="upload_ok_file.asp" -->
<%
set fc=nothing
set db = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
%>
<!--#include virtual="/dbConn.asp" -->
<%
sql = "select * from 테이블이름 where idx='" & idx &"' "
'response.write "sql=["&sql&"]<br>"
rs.open sql,db,1
if not rs.eof then
imagecount = rs("imagecount")
old_image1 = rs("imagename1")
old_image2 = rs("imagename2")
else
Response.Write("<script>")
Response.Write("window.alert('해당 자료를 찾을 수 없습니다.');")
Response.Write("history.go(-1);")
Response.Write("</script>")
Response.End
end if
sql = "update portfolio set "
sql = sql & "workplace='" & workplace & "'"
dim tempcount1, tempcount2
tempcount1 = 0
if Len(checkEmpty1) > 0 then
sql = sql & ", imagename1='" & checkEmpty1 & "'"
tempcount1 = tempcount1+1
end if
if Len(checkEmpty2) > 0 then
sql = sql & ", imagename2='" & checkEmpty2 & "'"
tempcount1 = tempcount1+1
end if
tempcount2 = 0
if delcheck1 = "y" then
sql = sql & ", imagename1=''"
tempcount2 = tempcount2+1
end if
if delcheck2 = "y" then
sql = sql & ", imagename2=''"
tempcount2 = tempcount2+1
end if
imagecount = imagecount - tempcount2 + tempcount1
sql = sql & ", imagecount=" & imagecount
sql = sql & " where idx=" & cint(idx)
'response.write sql & "<br>"
'Response.End
db.execute(sql)
' 첨부파일을 삭제한다.
Set objfs=Server.CreateObject("Scripting.FileSystemObject")
if delcheck1 = "y" then
DirectoryPath = Server.MapPath("\upload") & "\" & old_image1
'response.write DirectoryPath & "<br>"
objfs.DeleteFile(DirectoryPath)
end if
'===========================
if delcheck2 = "y" then
DirectoryPath = Server.MapPath("\upload") & "\" & old_image2
objfs.DeleteFile(DirectoryPath)
end if
'===========================
Set objfs = nothing
response.Write "<script type=""text/javascript"">"
response.Write "alert('수정되었습니다.');"
' response.Write "history.back();" ' 뒤로가기
response.Write "document.location.href = ""list.asp""" '특정페이지로 가기
response.Write "</script>"
response.end
%>
##### upload_file_ok.asp #####
아래 글쓰기 게시글 참조
( https://www.happyjung.com/bbs/board.php?bo_table=lecture&wr_id=890 )
##### edit.asp #####
<%@Language=VBScript%>
<%
response.expires = 0
uid = Request("uid")
set db = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
%>
<!--#include virtual="/dbConn.asp" -->
<%
sql = "select * from 테이블이름 where idx='" & idx &"' "
'response.write "sql = "&sql&"<br>"
rs.open sql,db,1
if not rs.eof then
idx = rs("idx")
name1 = rs("name1")
name2 = rs("name2")
imagename1 = rs("imagename1")
imagename2 = rs("imagename2")
else
Response.Write("<script>")
Response.Write("window.alert('해당 자료를 찾을 수 없습니다.');")
Response.Write("history.go(-1);")
Response.Write("</script>")
Response.End
end if
rs.close
'db.close
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.0 Transitional//EN" >
<html>
<head>
<title>업로드</title>
<script language="javascript">
<!--
function sendForm(){
document.fForm.submit()
}
//-->
</script>
</head>
<body>
<form name="fForm" method="post" action="edit_ok.asp" ENCTYPE="multipart/form-data">
<input type="hidden" name="uid" value="<%=uid%>">
<table width="600" border="0" cellpadding="0" cellspacing="1" bgcolor="#666666">
<tr>
<td width="80">항목</td>
<td><input name="name1" type="text" value="<%=name1%>"></td>
</tr>
<tr>
<td>파일 1</td>
<td><input NAME="file1" id="file1" type="file" />
<% if Len(imagename1) > 0 then %><br /><input type='checkbox' value='y' name='delcheck1' id='delcheck1' /><%=imagename1%><% end if %></td>
</tr>
<tr>
<td>파일 2</td>
<td><input NAME="file2" id="file2" type="file" />
<% if Len(imagename2) > 0 then %><br /><input type='checkbox' value='y' name='delcheck2' id='delcheck2' /><%=imagename2%><% end if %></td>
</tr>
<tr>
<td colspan="2" align="center"><input id="Button2" type="button" value="수정" onClick="javascript:sendForm();" /></td>
</tr>
</table>
</form>
</body>
</html>
##### edit_ok.asp #####
<%@Language=VBScript%>
<%
response.expires = 0
Set up_form = Server.CreateObject("DEXT.FileUpload")
up_form.UploadTimeout = 3600
up_form.DefaultPath = Server.MapPath(".\upload\") & "\"
FilePath = up_form.Save()
idx = up_form("idx")
name1 = up_form("name1")
name2 = up_form("name2")
delcheck1 = up_form("delcheck1")
delcheck2 = up_form("delcheck2")
dim fc, storedir, fexist
set fc = CreateObject("Scripting.FileSystemObject")
storedir=server.mappath(".\upload\")+"\"
'Response.Write "storedir = " & storedir & "<br>"
%>
<!--#include file="upload_ok_file.asp" -->
<%
set fc=nothing
set db = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
%>
<!--#include virtual="/dbConn.asp" -->
<%
sql = "select * from 테이블이름 where idx='" & idx &"' "
'response.write "sql=["&sql&"]<br>"
rs.open sql,db,1
if not rs.eof then
imagecount = rs("imagecount")
old_image1 = rs("imagename1")
old_image2 = rs("imagename2")
else
Response.Write("<script>")
Response.Write("window.alert('해당 자료를 찾을 수 없습니다.');")
Response.Write("history.go(-1);")
Response.Write("</script>")
Response.End
end if
sql = "update portfolio set "
sql = sql & "workplace='" & workplace & "'"
dim tempcount1, tempcount2
tempcount1 = 0
if Len(checkEmpty1) > 0 then
sql = sql & ", imagename1='" & checkEmpty1 & "'"
tempcount1 = tempcount1+1
end if
if Len(checkEmpty2) > 0 then
sql = sql & ", imagename2='" & checkEmpty2 & "'"
tempcount1 = tempcount1+1
end if
tempcount2 = 0
if delcheck1 = "y" then
sql = sql & ", imagename1=''"
tempcount2 = tempcount2+1
end if
if delcheck2 = "y" then
sql = sql & ", imagename2=''"
tempcount2 = tempcount2+1
end if
imagecount = imagecount - tempcount2 + tempcount1
sql = sql & ", imagecount=" & imagecount
sql = sql & " where idx=" & cint(idx)
'response.write sql & "<br>"
'Response.End
db.execute(sql)
' 첨부파일을 삭제한다.
Set objfs=Server.CreateObject("Scripting.FileSystemObject")
if delcheck1 = "y" then
DirectoryPath = Server.MapPath("\upload") & "\" & old_image1
'response.write DirectoryPath & "<br>"
objfs.DeleteFile(DirectoryPath)
end if
'===========================
if delcheck2 = "y" then
DirectoryPath = Server.MapPath("\upload") & "\" & old_image2
objfs.DeleteFile(DirectoryPath)
end if
'===========================
Set objfs = nothing
response.Write "<script type=""text/javascript"">"
response.Write "alert('수정되었습니다.');"
' response.Write "history.back();" ' 뒤로가기
response.Write "document.location.href = ""list.asp""" '특정페이지로 가기
response.Write "</script>"
response.end
%>
##### upload_file_ok.asp #####
아래 글쓰기 게시글 참조
( https://www.happyjung.com/bbs/board.php?bo_table=lecture&wr_id=890 )
댓글목록
등록된 댓글이 없습니다.