|
<% @ WebHandler Language = "C #" Class = "imageManager" %>
/**
* Created by visual studio2010
* User: xuheng
* Date: 12-3-7
* Time: PM
* To change this template use File | Settings | File Templates.
*/
Using System;
Using System. Web;
Using System. IO;
Using System. Text. RegularExpressions;
Public class imageManager: IHttpHandler
{
Public void ProcessRequest (HttpContext context)
{
Context. Response. ContentType = "text/plain ";
String [] paths = {"upload", "upload1"}; // list of directories to be traversed. It is best to use the thumbnail address. Otherwise, serious latency may occur when the network speed is slow.
String [] filetype = {". gif", ". png", ". jpg", ". jpeg", ". bmp"}; // file format allowed
String action = context. Server. HtmlEncode (context. Request ["action"]);
If (action = "get ")
{
String str = String. Empty;
Foreach (string path in paths)
{
DirectoryInfo info = new DirectoryInfo (context. Server. MapPath (path ));
// Directory Verification
If (info. Exists)
{
DirectoryInfo [] infoArr = info. GetDirectories ();
Foreach (DirectoryInfo tmpInfo in infoArr)
{
Foreach (FileInfo fi in tmpInfo. GetFiles ())
{
If (Array. IndexOf (filetype, fi. Extension )! =-1)
{
Str + = path + "/" + tmpInfo. Name + "/" + fi. Name + "ue_separate_ue ";
}
}
}
}
}
Context. Response. Write (str );
}
// Add Start ============================================ ==================================== 2013-05-12
// Delete the selected file
String pathDel = string. Empty; // it is best to use a thumbnail address. Otherwise, serious latency may occur when the network speed is slow.
String fileName = context. Server. HtmlEncode (context. Request ["fileName"]);
Bool isDeleted = false;
If (action = "del ")
{
Try
{
String fullPath = String. Empty;
Foreach (string path in paths)
{
PathDel = context. Server. MapPath (path );
DirectoryInfo info = new DirectoryInfo (pathDel );
// Directory Verification
If (info. Exists)
{
// Obtain the directory named after time under the directory C:... ueditornetupload. For example, 2013-05-12
DirectoryInfo [] infoArr = info. GetDirectories ();
Foreach (DirectoryInfo tmpInfo in infoArr)
{
Foreach (FileInfo fi in tmpInfo. GetFiles ())
{
// Determine whether the image type is specified, because the persistent attachment and image are in the same directory
If (Array. IndexOf (filetype, fi. Extension )! =-1)
{
If (fi. Name. Equals (fileName ))
{
FullPath = pathDel + "/" + tmpInfo. Name + "/" + fileName;
File. Delete (fullPath );
IsDeleted = true;
Break;
}
}
}
// Deleted and exclusive
If (isDeleted = true)
Break;
}
}
// Deleted and exclusive
If (isDeleted = true)
Break;
}
IsDeleted = false;
Context. Response. Write ("success ");
}
Catch
{
Context. Response. Write ("error ");
}
}
// Add End ============================================ ====================================== 2013-05-12
}
Public bool IsReusable
{
Get
{
Return false;
}
}
} |