HI, What i'm trying to do, is to let the user download a file hosted elsewhere with a different name. for example, we have the file: http://www.xx.com/file.rar I want when the user downloads the file from my site( http://www.my.com/download?f=file.rar, using header("Location ..) to download the file with the name xxaddaa.rar instead of file.rar The simplest way would be to add headers and use curl to get and print the file, but i don't want that due to bandwidth loss. Please advise! Thanks
Header used for the file name is Content-Disposition, but I doubt it works with 301 or 302 redirect. Here is example headers for outputting content as a file, try them: header('Content-Disposition: attachment; filename="filename.rar"'); header('Content-type: application/force-download'); header('Content-Transfer-Encoding: binary'); PHP:
How about something like this? <? //set to the URL of the file you want to download: $inPath = "http://somepage.com/hello.jpg"; //set to the local path where the file should be saved: $outPath = "/usr/local/htdocs/hello.jpg"; $in = fopen($inPath, "rb"); $out = fopen($outPath, "wb"); while ($chunk = fread($in,8192) ) { fwrite($out, $chunk, 8192); } fclose($in); fclose($out); ?> PHP: You could even variablize that so you could have a URL submit form to submit the source and end product save. All you would have to do is wait for it to finish, then download directly from where you saved it.