PHP file Service implements virtual mount other directories
Copy CodeThe code is as follows:
function Base64url_encode ($data) {
return RTrim (STRTR (Base64_encode ($data), ' +/', '-_ '), ' = ');
}
function Base64url_decode ($data) {
Return Base64_decode (Str_pad (STRTR ($data, '-_ ', ' +/'), strlen ($data)% 4, ' = ', str_pad_right));
}
function Array_verify ($var)
{
return Isset ($var) &&is_array ($var) && count ($var) >0;
}
function Format_file_size ($var)
{
if ($var <1024) return $var. ' B ';
if ($var <1048576) return ($var/1024.0). ' K ';
if ($var <1073741824) return ($var/1048576.0). ' M ';
Return ($var/1073741824.0). ' G ';
}
$dir = "F:";//Do not end with/
$path = "";
if (array_verify ($_get) &&isset ($_get["path"])
{
$path =base64url_decode ($_get["path"]);
Preg_match ("#^[^/].*$|^.*\.$|^\. *$|\./\.| /\.| \./# ", $path, $temp);
if (Array_verify ($temp))
{
Echo
'
';
echo "Warning Index.php?path=". $_get["Path"]. "Illegal URL
";
Exit
}
$path =preg_replace ("#[/\/]{2,}#", "/", $path);
}
if (Is_dir ($dir. $path))
{
Echo '
';
echo "Catalog". $path."
";
$dir _res=opendir ($dir. $path);
while ($filen =readdir ($dir _res))
{
if ($filen! = '. ') && $filen! = ' ... ')
{
if (Is_file ($dir. $path. ' /'. $filen))
{
Echo '. $filen. ' ('. Format_file_size (FileSize ($dir. $path. ' /'. $filen)). ")
\ n ";
}else
{
Echo '. $filen. "
\ n ";
}
}else if ($filen = = ' ... ')
{
Preg_match ("# ([^/]+/{1}) *[^/]+ (? =/) #", $path, $parent);
if (Array_verify ($parent))
{
Echo '. $filen. "
\ n ";
}else
{
Echo '. $filen. "
\ n ";
}
}
}
Echo '
';
}
else if (Is_file ($dir. $path))
{
$file _size = FileSize ($dir. $path);
Header ("Content-type:application/octet-stream");
Header ("Accept-ranges:bytes");
Header ("Accept-length:". $file _size);
Header ("content-disposition:attachment; Filename= ". BaseName ($dir. $path));
ReadFile ($dir. $path);//Large file please choose another way
}else
echo "WARNING: illegal access!";
?>