Quick code I made for filtering out extensions for my C# Uploader I'm making.
ExamplePHP Code:static Boolean Evaluate_Extension(String Extension)
{
String[] Block = new String[] {".exe", ".html", ".php" };
if (Block.Contains(Extension))
{
return false;
}
return true;
}
PHP Code:if(Evaluate_Extension(Path.GetExtension(@"C:\Users\Chad\Desktop\test.txt")) == true){
Console.WriteLine("Continue with process...");
}else{
Console.WriteLine("Inappropriate file!");
}
Results 1 to 4 of 4
Thread: [C#] Extension Filter
-
05-14-2011 12:23 AM #1
[C#] Extension Filter
-
05-15-2011 02:07 PM #2
- Join Date
- Oct 2009
- Posts
- 1,019
- Rep
- 255
You may want to start using ternary operators for those simple true/false if statements. Those five lines can be shortened to:
Also, it's not a good idea to rely on the filename passed by through the user as the determent for the file type. I can save an executable file as .jpg, and it would pass your blacklist, whereas it should get blocked. Food for thoughtPHP Code:return (Block.Contains(Extension)) ? false : true;
-
05-17-2011 04:38 AM #3
-
05-24-2011 02:21 AM #4





Reply With Quote
Bookmarks