Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- / **
- * This funtion will take a pattern and a folder as the argument and go thru it(recursivly if needed)and return the list of
- * all files in that folder.
- * Link: http://www.bin-co.com/php/scripts/filesystem/ls/
- * Arguments : $pattern - The pattern to look out for [OPTIONAL]
- * $folder - The path of the directory of which's directory list you want [OPTIONAL]
- * $recursivly - The funtion will traverse the folder tree recursivly if this is true. Defaults to false. [OPTIONAL]
- * $options - An array of values 'return_files' or 'return_folders' or both
- * Returns : A flat list with the path of all the files(no folders) that matches the condition given.
- * /
- function ls($pattern="*", $folder="", $recursivly=false, $options=array('return_files','return_folders')) {
- if($folder) {
- $current_folder = realpath('.');
- if(in_array('quiet', $options)) { // If quiet is on, we will suppress the 'no such folder' error
- if(!file_exists($folder)) return array();
- }
- if(!chdir($folder)) return array();
- }
- $get_files = in_array('return_files', $options);
- $get_folders= in_array('return_folders', $options);
- $both = array();
- $folders = array();
- // Get the all files and folders in the given directory.
- if($get_files) $both = glob($pattern, GLOB_BRACE + GLOB_MARK);
- if($recursivly or $get_folders) $folders = glob("*", GLOB_ONLYDIR + GLOB_MARK);
- //If a pattern is specified, make sure even the folders match that pattern.
- $matching_folders = array();
- if($pattern !== '*') $matching_folders = glob($pattern, GLOB_ONLYDIR + GLOB_MARK);
- //Get just the files by removing the folders from the list of all files.
- $all = array_values(array_diff($both,$folders));
- if($recursivly or $get_folders) {
- foreach ($folders as $this_folder) {
- if($get_folders) {
- //If a pattern is specified, make sure even the folders match that pattern.
- if($pattern !== '*') {
- if(in_array($this_folder, $matching_folders)) array_push($all, $this_folder);
- }
- else array_push($all, $this_folder);
- }
- if($recursivly) {
- // Continue calling this function for all the folders
- $deep_items = ls($pattern, $this_folder, $recursivly, $options); # :RECURSION:
- foreach ($deep_items as $item) {
- array_push($all, $this_folder . $item);
- }
- }
- }
- }
- if($folder) chdir($current_folder);
- return $all;
- }
- libxml_disable_entity_loader (false);
- $xmlfile = $_POST['body']; //file_get_contents('php://input');
- $ dom = new DOMDocument () ;
- $dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD);
- $creds = simplexml_import_dom($dom);
- $user = $creds->user;
- $pass = $creds->pass;
- echo "<html> <head> <link rel=\"stylesheet\" type=\"text/css\" href=\"./countrylane.css\"></head>";
- if ($user == "admin") {
- if ($pass == "0e1234") {
- echo "<p> The creds [ $user : $pass ] were correct! </p>";
- echo "<br>";
- print("<p> You won the directory listing! </p>");
- echo "<br>";
- $listing = ls("*");
- echo "<p>";
- print_r($listing);
- echo "</p>";
- } else {
- echo "Wrong password [ $user : $pass ]";
- }
- } else {
- echo "<p> Wrong creds [ $user : $pass ] </p>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement