I would like to upload some files with jQuery File Upload, but i want to filter file types by this code:
public class file : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
HttpPostedFile postedFile = context.Request.Files["file"];
string extension = Path.GetExtension(postedFile.FileName).ToLower();
string[] validExtensions = { ".jpg", ".jpeg", ".png", ".gif", ".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pps", ".ppsx" };
if (extension.IndexOf(extension) != -1)
{
// upload files here
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
this code works well, but when i rename file extensions (for example when rename x.exe to x.jpg) the above code, accept the file type and start to upload file.
How can i handle this problem?
You can't be absolutely sure that a file is of type X or Y (in your case an image) unless you try to open the posted file.
Nevertheless, you can do some test against your
HttpPostedFileI use the following code to do so
Hope this helps.