troubleshooting Question

adding a filename restriction to file-uplaoding

Avatar of galneweinhaw
galneweinhaw asked on
21 Comments1 Solution282 ViewsLast Modified:
What do I need to add to restrict files to those whose filenames begin with 2 numbers?  ie - "45dfsdf.log" and "111111" would be accepted but "a222" and "1two3.log" would be rejected?

SO far here is what I have:

Here is the form to uplaod the Data:

<!-- The data encoding type, enctype, MUST be specified as below --><form action="successorfail.php" method="post" enctype="multipart/form-data"><!-- MAX_FILE_SIZE must precede the file input field --><input type="hidden" name="MAX_FILE_SIZE" /> <!-- Name of input element determines name in $_FILES array -->Upload Eternal Campaign Log File: <input type="file" name="userfile" /> <input type="submit" /> </form>

and here is the processing page:

// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/home/happyhik/public_html/OtherStuff/EternalLogFiles/LogUploads/';
$uploadfile = $uploaddir . basename($HTTP_POST_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Possible file upload attack!\n";

echo 'Here is some more debugging info:';

print "</pre>";

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 21 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 21 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros