PHP File Service Implementation Virtual mount Other directory example _php instance

Source: Internet
Author: User
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!";

?>

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.