function checkExtraPDFs($doDelete = false, $onlyOld = false) { //list directory $submitPath = "../submit"; $fileList = list_directory($submitPath); //remove files that are less than an hour old from our list if ($onlyOld) { foreach ($fileList as $key => $filename) { if (time() - filemtime($submitPath . "/" . $filename) < 3600) { unset($fileList[$key]); } } } //get all submitted PDFs $result = mysql_query("SELECT submitted FROM applications WHERE submitted != ''"); while ($row = mysql_fetch_array($result)) { $submitFiles = explode(":", $row[0]); foreach ($submitFiles as $submitFile) { $index = array_search($submitFile . ".pdf", $fileList); if ($index !== FALSE) { unset($fileList[$index]); } } } $result = mysql_query("SELECT filename FROM recommendations WHERE filename != ''"); while ($row = mysql_fetch_array($result)) { $submitFile = $row[0]; $index = array_search($submitFile . ".pdf", $fileList); if ($index !== FALSE) { unset($fileList[$index]); } } $result = mysql_query("SELECT filename FROM purchase_order WHERE filename != ''"); while ($row = mysql_fetch_array($result)) { $submitFile = $row[0]; $index = array_search($submitFile . ".pdf", $fileList); if ($index !== FALSE) { unset($fileList[$index]); } } $pdfArray = array(); foreach ($fileList as $file) { $path = $submitPath . "/" . $file; $pdfArray[] = $path; if ($doDelete) { unlink($path); } } return $pdfArray; }
/** * Lists contens of a given directory and returns array with entries * * @param $directory string. source path of the root directory * @param $recursive bool. to continue to return subdirectories * * @access public * @return array directory entries * @author Travis van der Font */ function list_directory($directory, $recursive = FALSE) { $array_items = array(); if ($handle = opendir($directory)) { while (($file = readdir($handle)) !== FALSE) { if ($file != '.' && $file != '..') { if (is_dir($directory . '/' . $file)) { if ($recursive) { $array_items = array_merge($array_items, list_directory($directory . '/' . $file, $recursive)); } $array_items[] = preg_replace("/\\/\\//si", "/", $directory . '/' . $file); } else { $array_items[] = preg_replace("/\\/\\//si", "/", $directory . '/' . $file); } } } closedir($handle); } return (array) $array_items; }
protected function list_directory($directory, $recursive = FALSE) { if (defined('STRICT_TYPES') && CAMEL_CASE == '1') { return (array) self::parameters(['directory' => DT::STRING, 'recursive' => DT::BOOL])->call(__FUNCTION__)->with($directory, $recursive)->returning(DT::TYPE_ARRAY); } else { return (array) list_directory($directory, $recursive); } }
function dispatch_uri($uri) { $path = find_path($uri); if (strlen($path) == 0) { path_not_found($uri); } elseif (!is_dir($path)) { send_file($path); } elseif ($path[strlen($path) - 1] != '/') { redirect("{$uri}/"); } else { list_directory($uri, $path); } }
} function file_title_case($filename) { return ucwords($filename); } function list_directory($dir) { $dir_list = array(); // Only add .txt/.pdf files foreach (glob($dir . "*.{txt,pdf}", GLOB_BRACE) as $file) { array_push($dir_list, basename($file)); } natcasesort($dir_list); // case-insensitive sort return $dir_list; } // print out html echo "\t" . '<ul>' . "\r\n\t"; $directory_array = list_directory(WP_CONTENT_DIR . $default_dir); global $pagename; if ('minutes' === $pagename) { rsort($directory_array); } foreach ($directory_array as $fn) { $fn_ext = $fn; $fn = file_ext_strip($fn); $fn = file_replace_spacer($fn); $fn = file_title_case($fn); echo "<li><a href=" . chr(34) . content_url() . $default_dir . $fn_ext . chr(34) . ">" . $fn . "</a></li>\r\n\t"; } echo '</ul>' . "\r\n\t";