I use something like this to sanitize form posts...
- Code: Select all
$val = preg_replace("/[^a-zA-Z0-9\-\$\/\s]/", "", $val);
However, I guess I don't have enough info on what you want to do.. here is how I get a file from another directory.. on my page I get the content of a directory... not sure preg_match is the method I would use... explain a bit more what you want to do.. for now here is this..
- Code: Select all
$dirname = "INC";
$dir = opendir($dirname);
echo '<center><form method="post" action=""><select name="file">';
while(false != ($file = readdir($dir))) {
if(($file != ".") and ($file != "..")) {
echo("<option value='$file'>$file</option>");
}
}
echo ' <input type="submit" name="submit" value="View File"></form>';
That gives me a drop down box of the files in the directory I chose... you could go further and restrict the list to a file type I suppose. Then create the code to view the file...
- Code: Select all
if ($_POST["submit"] == "View File") {
$file = $_POST["file"];
$fileout = file_get_contents("$dirname/$file");
echo $fileout;
}
I just slapped that together.. so don't hate.. I think it will work though.. and for security the drop down list, atleast you aren't taking in any user input that way...