Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Ukrycie bezpośredniego adresu do pliku
Forum PHP.pl > Forum > PHP
szymek001
Dzień dobry, w jaki sposób mogę ukryć bezpośredni adres do pliku na innym serwerze niż strona z której będę linkować do plików?

Chodzi mi o to że ze strony mojastrona.pl chce podlinkować pliki które są na serwerach mojepliki.pl, mojepliki2.pl itd.
Wiem, że jest to wykonalne, aby realny adres do tych plików ukryć, znalazłem parę skryptów do tego, ale są bardzo stare, ten np.: http://www.kavoir.com/2009/05/php-hide-the...php-script.html jest z 2009 roku.

Czy wie ktoś jak teraz można osiągnąć taki efekt i koniecznie żeby działało z linkami do innego serwera.

Tutaj jeszcze coś mam, ale to z roku 2007: http://w-shadow.com/blog/2007/08/12/how-to...nload-with-php/
nospor
I co z tego ze stare? Tak sie wlasnie robi.
szymek001
tak, ale jak to zrobić dla linków zewnętrznych?

  1. function output_file($file, $name, $mime_type='')
  2. {
  3. /*
  4.  This function takes a path to a file to output ($file),
  5.  the filename that the browser will see ($name) and
  6.  the MIME type of the file ($mime_type, optional).
  7.  
  8.  If you want to do something on download abort/finish,
  9.  register_shutdown_function('function_name');
  10.  */
  11. if(!is_readable($file)) die('File not found or inaccessible!');
  12.  
  13. $size = filesize($file);
  14. $name = rawurldecode($name);
  15.  
  16. /* Figure out the MIME type (if not specified) */
  17. $known_mime_types=array(
  18. "pdf" => "application/pdf",
  19. "txt" => "text/plain",
  20. "html" => "text/html",
  21. "htm" => "text/html",
  22. "exe" => "application/octet-stream",
  23. "zip" => "application/zip",
  24. "doc" => "application/msword",
  25. "xls" => "application/vnd.ms-excel",
  26. "ppt" => "application/vnd.ms-powerpoint",
  27. "gif" => "image/gif",
  28. "png" => "image/png",
  29. "jpeg"=> "image/jpg",
  30. "jpg" => "image/jpg",
  31. "php" => "text/plain"
  32. );
  33.  
  34. if($mime_type==''){
  35. $file_extension = strtolower(substr(strrchr($file,"."),1));
  36. if(array_key_exists($file_extension, $known_mime_types)){
  37. $mime_type=$known_mime_types[$file_extension];
  38. } else {
  39. $mime_type="application/force-download";
  40. };
  41. };
  42.  
  43. @ob_end_clean(); //turn off output buffering to decrease cpu usage
  44.  
  45. // required for IE, otherwise Content-Disposition may be ignored
  46. if(ini_get('zlib.output_compression'))
  47. ini_set('zlib.output_compression', 'Off');
  48.  
  49. header('Content-Type: ' . $mime_type);
  50. header('Content-Disposition: attachment; filename="'.$name.'"');
  51. header("Content-Transfer-Encoding: binary");
  52. header('Accept-Ranges: bytes');
  53.  
  54. /* The three lines below basically make the
  55.   download non-cacheable */
  56. header("Cache-control: private");
  57. header('Pragma: private');
  58. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  59.  
  60. // multipart-download and download resuming support
  61. if(isset($_SERVER['HTTP_RANGE']))
  62. {
  63. list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2);
  64. list($range) = explode(",",$range,2);
  65. list($range, $range_end) = explode("-", $range);
  66. $range=intval($range);
  67. if(!$range_end) {
  68. $range_end=$size-1;
  69. } else {
  70. $range_end=intval($range_end);
  71. }
  72.  
  73. $new_length = $range_end-$range+1;
  74. header("HTTP/1.1 206 Partial Content");
  75. header("Content-Length: $new_length");
  76. header("Content-Range: bytes $range-$range_end/$size");
  77. } else {
  78. $new_length=$size;
  79. header("Content-Length: ".$size);
  80. }
  81.  
  82. /* output the file itself */
  83. $chunksize = 1*(1024*1024); //you may want to change this
  84. $bytes_send = 0;
  85. if ($file = fopen($file, 'r'))
  86. {
  87. if(isset($_SERVER['HTTP_RANGE']))
  88. fseek($file, $range);
  89.  
  90. while(!feof($file) &&
  91. ($bytes_send<$new_length)
  92. )
  93. {
  94. $buffer = fread($file, $chunksize);
  95. print($buffer); //echo($buffer); // is also possible
  96. flush();
  97. $bytes_send += strlen($buffer);
  98. }
  99. fclose($file);
  100. } else die('Error - can not open file.');
  101.  
  102. die();
  103. }
  104.  
  105. /*********************************************
  106.   Example of use
  107. **********************************************/
  108.  
  109. /*
  110. Make sure script execution doesn't time out.
  111. Set maximum execution time in seconds (0 means no limit).
  112. */
  113. $file_path='that_one_file.txt';
  114. output_file($file_path, 'some file.txt', 'text/plain');

ten skrypt działa tylko jeśli $file_path to adres pliku umieszczonego na tym samym serwerze..
nospor
1) Twoj serwer ma miec dostep do plikow z innego serwera
2) Musisz miec włączoną opcję
http://cz1.php.net/manual/en/filesystem.co...allow-url-fopen
3) Jesli Twoj serwer nie ma dostepu do zewnetrznych plikow przez ftp, to musiszz uzyc chocby ftp czy w jakis inny sposob miec dostep do tych plikow. Cudow nie ma.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.