| version 1.2, 2002/06/16 10:22:29 |
version 1.3, 2002/07/21 22:49:42 |
|
|
| <? |
<?php |
| |
|
| /************************************************************************** |
/************************************************************************** |
| * |
* |
| * file.php |
* file.php |
|
|
| * |
* |
| * where /fm/ is where phpWebFileManager is installed. |
* where /fm/ is where phpWebFileManager is installed. |
| * |
* |
| * Then change $phpWebFileManager_LINKS_PREFIX in your config.inc.php file |
* Then change $fm_cfg['url'] in your config.inc.php file * to be "file/". |
| * to be "file/"; |
* If you can't use mod_rewrite for whatever reason, set $fm_cfg['url'] to |
| * |
* "file.php?path=". (untested) |
| * If you can't use mod_rewrite for whatever reason, set |
|
| * $phpWebFileManager_LINKS_PREFIX to "file.php?path=". (untested) |
|
| * |
* |
| * You should also adjust the $APACHE_MIME_TYPES variable below to point |
* You should also adjust the $APACHE_MIME_TYPES variable below to point |
| * at your apache "mime.types" file. |
* at your apache "mime.types" file. |
| * |
* |
| * Tony J. White, tjw@tjw.org 2002-04-15 |
* Tony J. White, tjw@tjw.org, 2002-04-15 |
| **************************************************************************/ |
**************************************************************************/ |
| |
|
| include_once 'config.inc.php'; |
|
| |
|
| $APACHE_MIME_TYPES = '/etc/httpd/conf/apache-mime.types'; |
|
| /* |
/* |
| * Put your access restriction code here. |
* phpWebFileManager initialization |
| * |
* |
| * include("auth.php"); |
* Config file is read from init.inc.php file. |
| */ |
*/ |
| |
|
| |
$phpWebFileManager_INIT_FILE = dirname(__FILE__) |
| |
. (strlen(dirname(__FILE__)) > 0 ? '/' : '') |
| |
. 'init.inc.php'; |
| |
|
| |
if (! @file_exists($phpWebFileManager_INIT_FILE)) { |
| |
exit; |
| |
} |
| |
|
| |
require_once $phpWebFileManager_INIT_FILE; |
| |
require_once $PN_PathPrefix . 'lib/fnc.append_slash.php'; |
| |
|
| |
// note that this constant will not remain in future |
| |
// it will be moved into config file, where array of possible |
| |
// Apache mime.types locations will be present |
| |
$APACHE_MIME_TYPES = '/etc/httpd/conf/apache-mime.types'; |
| |
|
| // parse apache mime.types |
/* |
| if(is_readable($GLOBALS["APACHE_MIME_TYPES"])) { |
* Permission check |
| $mime_types = file($GLOBALS["APACHE_MIME_TYPES"]); |
*/ |
| if(is_array($mime_types)) while(list(,$line) = each($mime_types)) { |
if (! $fm_cfg['perm']['file']['view']) { |
| if(substr($line, 0, 1) == "#") continue; |
echo 'Insufficient privileges for file viewing.'; |
| $parts = preg_split("/(\s+)/", $line); |
} else { |
| if(is_array($parts)) if(sizeof($parts) > 2) { |
|
| list(,$mime) = each($parts); |
/* |
| while(list(,$ext) = each($parts)) { |
* Parsing of apache-mime.types file |
| if(trim($ext) != "") { |
*/ |
| $mimes_by_ext[$ext] = $mime; |
|
| |
if (is_readable($GLOBALS["APACHE_MIME_TYPES"])) { |
| |
$mime_types = file($GLOBALS["APACHE_MIME_TYPES"]); |
| |
if (is_array($mime_types)) { |
| |
|
| |
while (list(,$line) = each($mime_types)) { |
| |
if ($line[0] == '#') |
| |
continue; |
| |
|
| |
$parts = preg_split("/(\s+)/", $line); |
| |
if (is_array($parts) && sizeof($parts) > 2) { |
| |
list(,$mime) = each($parts); |
| |
while (list(,$ext) = each($parts)) { |
| |
if (trim($ext) != '') |
| |
$mimes_by_ext[$ext] = $mime; |
| |
} |
| } |
} |
| } |
} |
| } |
|
| |
|
| |
} |
| } |
} |
| } |
|
| |
|
| |
/* |
| |
* Creating $file variable |
| |
*/ |
| |
|
| |
$file = append_slash($fm_cfg['dir']['root']) . substr($path, 1); |
| |
|
| |
/* |
| |
* Writting file on output |
| |
*/ |
| |
|
| |
if (file_exists($file) && is_readable($file)) { |
| |
header('Content-length: '.filesize($file)); |
| |
if (preg_match("/.*\.([a-z]{2,5})$/i", $file, $matches) |
| |
&& trim($mimes_by_ext[$matches[1]]) != '') { |
| |
header('Content-type: '.trim($mimes_by_ext[$matches[1]])); |
| |
} else { |
| |
header('Content-type: text/plain'); |
| |
} |
| |
|
| $file = $phpWebFileManager_ROOT_DIR."/".$path; |
readfile($file); |
| $file = $path; /* This line was added */ |
} else { |
| if(file_exists($file) && is_readable($file)) { |
echo "File '$file' not found or is not readable."; |
| header("Content-length: ".filesize($file)); |
|
| if(preg_match("/.*\.([a-z]{2,5})$/i", $file, $matches)) { |
|
| if(trim($mimes_by_ext[$matches[1]]) != "") |
|
| header("Content-type: " |
|
| .trim($mimes_by_ext[$matches[1]])); |
|
| else |
|
| header("Content-type: text/plain"); |
|
| } |
} |
| else header("Content-type: text/plain"); |
|
| readfile($file); |
|
| } |
} |
| |
|
| ?> |
?> |