Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is how I would do it.</p> <pre><code>&lt;?php function getFile($file_location) { header('Content-Description: File Transfer'); header('Content-type: application/exe'); header('Content-Disposition: attachment; filename="supercoolFF.exe"'); header('Content-Transfer-Encoding: binary'); ob_end_clean(); $url_info = parse_url($file_location); if (!isset($url_info['query'])) $url_info['query'] = ''; $http = fsockopen($url_info['host'],$url_info['port']); $req = "GET " . $url_info['path'] . "?" . $url_info['query'] . " HTTP/1.1\r\n"; $req .= "Host: " . $url_info['host'] . ":" . $url_info['port'] . "\r\n"; $req .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"; $req .= "User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8\r\n"; $req .= "Accept-Language: en-us,en;q=0.5\r\n"; $req .= "Accept-Encoding: gzip,deflate\r\n"; $req .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"; if ($len = strlen($url_info['query']) { $req .= 'Content-Length: ' . $len . "\r\n"; $req .= "Connection: Close\r\n\r\n"; $req .= $query . "\r\n\r\n"; } else { $req .= "Connection: Keep-Alive\r\n\r\n"; } fputs($http, $req); $content = ""; $content_encountered = FALSE; ob_end_clean(); while(strlen($part = fgets($http, 4096))) { if ($content_encountered) { echo $part; $content .= $part; } if ($part == "\r\n") { $content_encountered = TRUE; } } fclose($http); exit; } $filename='Firefox%20Setup%203.6.13.exe?'; $file_path='http://ftp.byfly.by:80/pub/mozilla.org/firefox/releases/3.6.13/win32/fr'; getFile($file_path . '/' . $filename); </code></pre> <p>Of course, it would be better to do a HEAD request first to get the filesize and include a Content-Length header in the response so the user can have some idea about how long it is going to take. Or, you can hardcode that number, if you are always going to be serving up the same file.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload