Welcome Guest, Not a member yet? Register   Sign In
File Helper and Canonicalization issues
#2

[eluser]mddd[/eluser]
Option 1 : Don't let the user enter the name. Just give the file a logical name, for instance the date and time of creation. Or a random string. Whether this works for you or not depends on what the file is going to be used for.

Option 2 : Use a regular expression and check the name against that. That way you can choose which characters you want to allow. For instance:
Code:
if (!preg_match('/^[a-z0-9\.\-_]+$/i', $filename) echo 'This file name is incorrect!';
In this example, letters, numbers, dashes and underscores are allowed.

Option 3 : Extract the last part of the name. You could use basename() for that, but that may not be totally secure because the user can enter anything, including things that wouldn't normally be in a file path.

Option 1 is the most safe, followed by option 2.


Messages In This Thread
File Helper and Canonicalization issues - by El Forum - 07-08-2010, 07:10 AM
File Helper and Canonicalization issues - by El Forum - 07-08-2010, 09:13 AM
File Helper and Canonicalization issues - by El Forum - 07-08-2010, 09:31 AM
File Helper and Canonicalization issues - by El Forum - 07-08-2010, 10:02 AM
File Helper and Canonicalization issues - by El Forum - 07-08-2010, 10:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB