From another server without downloading to your server:
header('Location: http://thirdparty.com/file.ext');
Without downloading the file locally, you do not have authorization on the external server, so you must tell the browser what to do, and thus the redirect header, it will tell the server to go directly to the specified url, loading the download.
From your server you will do:
if (file_exists($file)) { if(false !== ($handler = fopen($file, 'r'))) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); //Remove //Send the content in chunks while(false !== ($chunk = fread($handler,4096))) { echo $chunk; } } exit; } echo "<h1>Content error</h1><p>The file does not exist!</p>";
Taken from another question I answered
RobertPitt
source share