一个ASP版的图片浏览管理器
类别: ASP教程
下面是很简洁的代码
<%@ Language=VBScript %>
<% Option Explicit %>
<%
Const ImageFilePath = "images"
Const DeleteButtonLabel = "Delete Selected Images"
Dim objFSO
Dim objFolder
Dim objFile
Dim strFileName
Dim strFileExtension
Dim blnShowImages
If Request.QueryString("ShowImages") = "" Then
blnShowImages = False
Else
blnShowImages = CBool(Request.QueryString("ShowImages"))
End If
If Request.Form("btnDelete") = DeleteButtonLabel Then
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
For Each strFileName In Request.Form("delete")
objFSO.DeleteFile(Server.MapPath(ImageFilePath & "/" & _
strFileName))
Next
Set objFSO = Nothing
End If
%>
<html>
<head>
<title>ASP 101 Image Browser & Killer!</title>
</head>
<body>
<form action="<%= Request.ServerVariables("URL") %>" method="post">
<table border="1">
<tr>
<th>Image Name</th>
<th>Image <a href="<%= Request.ServerVariables("URL") %>?
ShowImages=<%= Not blnShowImages %>">(Toggle Display)</a></th>
<th>Delete This Image</th>
</tr>
<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(ImageFilePath))
For Each objFile In objFolder.Files
strFileExtension = LCase(Mid(objFile.Name, _
InStrRev(objFile.Name, ".", -1, 1) + 1))
If strFileExtension = "gif" Or strFileExtension = "jpg" Or _
strFileExtension = "jpeg" Then
\' Original image file identification option:
\'If objFile.Type = "GIF Image" Or _
objFile.Type = "JPEG Image" Then
%>
<tr>
<td>
<a href="<%= ImageFilePath & "/" & objFile.Name %>">
<%= objFile.Name %></a>
</td>
<%
If blnShowImages Then
%>
<td>
<img src="<%= ImageFilePath & "/" & objFile.Name %>" />
</td>
<%
Else
%>
<td>
<a href="<%= ImageFilePath & "/" & objFile.Name %>">
View Image</a>
</td>
<%
End If
%>
<td align="center">
<input type="checkbox" name="delete"
value="<%= objFile.Name %>" />
</td>
<%
End If
Next
Set objFolder = Nothing
Set objFSO = Nothing
%>
<tr>
<td colspan="3" align="right">
<input type="submit" name="btnDelete"
value="<%= DeleteButtonLabel %>">
</td>
</tr>
</table>
</form>
</body>
</html>
执行删除操作时,一定要注意,如果在程序里不加删除确认提示,程序将不能撤消删除操作。
<%@ Language=VBScript %>
<% Option Explicit %>
<%
Const ImageFilePath = "images"
Const DeleteButtonLabel = "Delete Selected Images"
Dim objFSO
Dim objFolder
Dim objFile
Dim strFileName
Dim strFileExtension
Dim blnShowImages
If Request.QueryString("ShowImages") = "" Then
blnShowImages = False
Else
blnShowImages = CBool(Request.QueryString("ShowImages"))
End If
If Request.Form("btnDelete") = DeleteButtonLabel Then
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
For Each strFileName In Request.Form("delete")
objFSO.DeleteFile(Server.MapPath(ImageFilePath & "/" & _
strFileName))
Next
Set objFSO = Nothing
End If
%>
<html>
<head>
<title>ASP 101 Image Browser & Killer!</title>
</head>
<body>
<form action="<%= Request.ServerVariables("URL") %>" method="post">
<table border="1">
<tr>
<th>Image Name</th>
<th>Image <a href="<%= Request.ServerVariables("URL") %>?
ShowImages=<%= Not blnShowImages %>">(Toggle Display)</a></th>
<th>Delete This Image</th>
</tr>
<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(ImageFilePath))
For Each objFile In objFolder.Files
strFileExtension = LCase(Mid(objFile.Name, _
InStrRev(objFile.Name, ".", -1, 1) + 1))
If strFileExtension = "gif" Or strFileExtension = "jpg" Or _
strFileExtension = "jpeg" Then
\' Original image file identification option:
\'If objFile.Type = "GIF Image" Or _
objFile.Type = "JPEG Image" Then
%>
<tr>
<td>
<a href="<%= ImageFilePath & "/" & objFile.Name %>">
<%= objFile.Name %></a>
</td>
<%
If blnShowImages Then
%>
<td>
<img src="<%= ImageFilePath & "/" & objFile.Name %>" />
</td>
<%
Else
%>
<td>
<a href="<%= ImageFilePath & "/" & objFile.Name %>">
View Image</a>
</td>
<%
End If
%>
<td align="center">
<input type="checkbox" name="delete"
value="<%= objFile.Name %>" />
</td>
<%
End If
Next
Set objFolder = Nothing
Set objFSO = Nothing
%>
<tr>
<td colspan="3" align="right">
<input type="submit" name="btnDelete"
value="<%= DeleteButtonLabel %>">
</td>
</tr>
</table>
</form>
</body>
</html>
执行删除操作时,一定要注意,如果在程序里不加删除确认提示,程序将不能撤消删除操作。
- 上一篇: 利用ASP打造网站论坛DIY
- 下一篇: 使用FSO把文本信息导入数据库
-= 资 源 教 程 =-
文 章 搜 索