This is my first time translating an article, so please forgive me for any shortcomings.
The reason why India is now a major software exporter is that it is superior to us in many places. One of the first advantages is that the official language of India is English, which brings unique advantages to Indian programmers who use English as a programming language. For those of us in the IT industry, we should also strengthen our English training.
Introduction If you have a website that has been running for more than two months, you may have noticed that a lot of image files have accumulated on your website. Although we all try our best to name these picture files well, when we browse the file names of these pictures, it is always difficult for us to remember the special meaning or use of some picture file names.
At this time, we usually open those pictures with the browser repeatedly to see what pictures they are? At this time, this ASP code can be used as a picture browser (and cleaner) to browse these pictures and perform cleaning operations.
coding:
In fact, this program is a list page containing all the pictures in a certain directory, using the FileSystemObject object to list these picture files (gif and jpeg files).
Add a link toggle display to the page to control whether to display the image. When you have a lot of files and don't want to load them all, you can just let an image on the page display a link. On the contrary, if you are not sure what some file names mean, this function will be a good help for you to clean up.
The following is very concise code
<%@ 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>
When performing a deletion operation, be sure to note that if there is no deletion confirmation prompt in the program, the program will not be able to undo the deletion operation.
Conclusion People will never use ASP to build large-scale scalable websites. (Translator's note: This sentence is not very appropriate without translation. According to my work experience, ASP can completely build large-scale website systems. In terms of ASP, I have participated in the construction of large-scale corporate intranets, mobile industry applications, etc.) But sometimes you can use this to simplify your work, even if the code is never published on the WEB.
To obtain the code, you can download the discussion ZIP file containing this code from the root directory of http://www.weiw.com . After the code is executed, all images under http://www.weiw.com/images/ will be displayed.
You can change the value of the ImageFilePath constant. You can also put some virtual paths here and the code will use Server.MapPath to determine the appropriate physical path. You can easily specify certain locations on your website. For example, changing the value of that constant from "images" to "/images" would point the program to the images directory in the root directory of the website. In the same way, the value of ImageFilePath can be modified to achieve the same purpose.
Second: When writing this code, I simply used the file type on my machine. This only works smoothly on my machine. It turns out that the description of the file type can change the basis of your file union. In order to get the extensions you choose to display those based on such files instead of their type. I have implemented this functionality in the code in this ZIP file. This is now the latest version of the program.