PHP File Services," Virtual mounts " other directories

Source: Internet
Author: User
Temporarily not supported, breakpoint download.
  1. function Base64url_encode ($data) {
  2. return RTrim (STRTR (Base64_encode ($data), ' +/', '-_ '), ' = ');
  3. }
  4. function Base64url_decode ($data) {
  5. Return Base64_decode (Str_pad (STRTR ($data, '-_ ', ' +/'), strlen ($data)% 4, ' = ', str_pad_right));
  6. }
  7. function Array_verify ($var)
  8. {
  9. return Isset ($var) &&is_array ($var) && count ($var) >0;
  10. }
  11. function Format_file_size ($var)
  12. {
  13. if ($var <1024) return $var. ' B ';
  14. if ($var <1048576) return ($var/1024.0). ' K ';
  15. if ($var <1073741824) return ($var/1048576.0). ' M ';
  16. Return ($var/1073741824.0). ' G ';
  17. }
  18. $dir = "F:";//Do not end with/
  19. $path = "";
  20. if (array_verify ($_get) &&isset ($_get["path"])
  21. {
  22. $path =base64url_decode ($_get["path"]);
  23. Preg_match ("#^[^/].*$|^.*\.$|^\. *$|\./\.| /\.| \./# ", $path, $temp);
  24. if (Array_verify ($temp))
  25. {
  26. Echo
  27. '
  28. ';
  29. echo "Warning Index.php?path=". $_get["Path"]. "Illegal URL
    ";
  30. Exit
  31. }
  32. $path =preg_replace ("#[/\/]{2,}#", "/", $path);
  33. }
  34. if (Is_dir ($dir. $path))
  35. {
  36. Echo '
  37. ';
  38. echo "Catalog ". $path. "

    ";
  39. $dir _res=opendir ($dir. $path);
  40. while ($filen =readdir ($dir _res))
  41. {
  42. if ($filen! = '. ') && $filen! = ' ... ')
  43. {
  44. if (Is_file ($dir. $path. ' /'. $filen))
  45. {
  46. Echo '. $filen. ' ('. Format_file_size (FileSize ($dir. $path. ' /'. $filen)). ")
    \ n ";
  47. }else
  48. {
  49. Echo '. $filen. "
    \ n ";
  50. }
  51. }else if ($filen = = ' ... ')
  52. {
  53. Preg_match ("# ([^/]+/Small left] *[^/]+ (? =/) #", $path, $parent);
  54. if (Array_verify ($parent))
  55. {
  56. Echo '. $filen. "
    \ n ";
  57. }else
  58. {
  59. Echo '. $filen. "
    \ n ";
  60. }
  61. }
  62. }
  63. Echo '
  64. ';
  65. }
  66. else if (Is_file ($dir. $path))
  67. {
  68. $file _size = FileSize ($dir. $path);
  69. Header ("Content-type:application/octet-stream");
  70. Header ("Accept-ranges:bytes");
  71. Header ("Accept-length:". $file _size);
  72. Header ("content-disposition:attachment; Filename= ". BaseName ($dir. $path));
  73. ReadFile ($dir. $path);//Large file please choose another way
  74. }else
  75. echo "WARNING: illegal access!";
  76. ?>
Copy Code
  • 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.