function SearchFiles($path) { $sortedData = array(); $dircont = scandir($path); if (count($dircont) > 0) { foreach ($dircont as $file) { if (is_file($path . $file)) { if (ValidFileExtension($file)) { $sortedData[] = array(0 => PathToUrl($path) . $file, 1 => $file); } } elseif ($file !== '.' && $file !== '..') { array_merge($sortedData, SearchFiles($path . $file . '/')); } } } return $sortedData; }
<?php require_once 'config.php'; require_once 'functions.php'; if (!defined('LIBRARY_FOLDER_PATH')) { define('LIBRARY_FOLDER_PATH', 'uploads/'); } if (!defined('LIBRARY_FOLDER_PATH')) { $pageURL = 'http'; if (isset($_SERVER["HTTPS"]) and $_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; } if (preg_match("/(.*)\\/search\\.php/", $pageURL, $matches)) { define('LIBRARY_FOLDER_URL', $matches[1] . '/uploads/'); } } $output = SearchFiles(LIBRARY_FOLDER_PATH); header("Content-type: text/plain;"); echo json_encode($output); exit;