function send_file($name) { OB_END_CLEAN(); $path = $name; //"../temp/".$name; if (!IS_FILE($path) or CONNECTION_STATUS() != 0) { return FALSE; } HEADER("Cache-Control: no-store, no-cache, must-revalidate"); HEADER("Cache-Control: post-check=0, pre-check=0", FALSE); HEADER("Pragma: no-cache"); HEADER("Expires: " . GMDATE("D, d M Y H:i:s", MKTIME(DATE("H") + 2, DATE("i"), DATE("s"), DATE("m"), DATE("d"), DATE("Y"))) . " GMT"); HEADER("Last-Modified: " . GMDATE("D, d M Y H:i:s") . " GMT"); HEADER("Content-Type: application/octet-stream"); HEADER("Content-Length: " . (string) FILESIZE($path)); HEADER("Content-Disposition: inline; filename={$name}"); HEADER("Content-Transfer-Encoding: binary\n"); if ($file = FOPEN($path, 'rb')) { while (!FEOF($file) and CONNECTION_STATUS() == 0) { print FREAD($file, 1024 * 8); FLUSH(); } FCLOSE($file); } return CONNECTION_STATUS() == 0 and !CONNECTION_ABORTED(); }
function BUILD_DIRECTORY_TREE($SOURCE, $PREVIOUS) { /* This code build the structure of the tree directory processing the output of the dir PHP command in a recursive way, using the current file filter criteria and storing the values in a set of arrays that must be shared among the rest of the functions in the programs. The first time call variable $SOURCE is the path choosen to be shown in a tree the variable $_SESSION['Numfile'] the value of -1 and the variable $PREVIOUS=0. */ $_SESSION['Numfile']++; //the first time from -1 to numfile=0 $_SESSION['Folder_Name'][$_SESSION['Numfile']] = BASENAME($SOURCE); $_SESSION['Father'][$_SESSION['Numfile']] = $PREVIOUS; $_SESSION['Numbytes'][$_SESSION['Numfile']] = 0; $_SESSION['File_Date'][$_SESSION['Numfile']] = ""; $_SESSION['Children_Files'][$_SESSION['Numfile']] = 0; $_SESSION['Children_Subdirs'][$_SESSION['Numfile']] = 0; $_SESSION['Level_Tree'][$_SESSION['Numfile']] = SUBSTR_COUNT($SOURCE, DIRECTORY_SEPARATOR) - $_SESSION['Levels_Fixed_Path']; $_SESSION['Folder_Type'][$_SESSION['Numfile']] = "Folder"; $_SESSION['Opened_Folder'][$_SESSION['Numfile']] = 0; if (IS_FILE($SOURCE)) { $_SESSION['Folder_Type'][$_SESSION['Numfile']] = "File"; $_SESSION['Numbytes'][$_SESSION['Numfile']] = FILESIZE($SOURCE); $_SESSION['File_Date'][$_SESSION['Numfile']] = FILEMTIME($SOURCE); return; //finish this branch and go up one level the recursion process } // ok is a directory $PREVIOUS = $_SESSION['Numfile']; // reading source path $DIR = DIR($SOURCE); while (false !== ($ENTRY = $DIR->READ())) { if ($ENTRY != '.' && $ENTRY != '..') { // directory has children $NEW_DIR = $SOURCE . DIRECTORY_SEPARATOR . $ENTRY; if (IS_DIR($NEW_DIR) || IS_FILE($NEW_DIR) && IS_FILE_TO_DISPLAY($ENTRY)) { // go down one level the recursion process BUILD_DIRECTORY_TREE($NEW_DIR, $PREVIOUS); } } } $DIR->CLOSE(); return; //finish this branch }