I have a host for store data and a download host (this host doesn't have database). I want to read a file from download host in store host and give it to user for download but I don't want to use monthly bandwidth transfer of store host when user is downloading file and just use download host bandwidth transfer.
There are two ways that I know:
ftp_get
download the file and save it in a local file and then setheader
for download. I don't want use this way because download file in store host.// in store host $local_file = 'app.apk'; $ftp_file = '/uploads/2015/06/1eb6a628c60bb69a6b6092d03e252c29.apk'; // download file and save it in local ftp_get($conn_id , $local_file, $ftp_file, FTP_BINARY); $file_name = 'app.apk'; $file_size = filesize($local_file); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $file_name); header('Content-Transfer-Encoding: binary'); header('Connection: Keep-Alive'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . $file_size); readfile($local_file);
I don't know
file_get_contents
use bandwidth transfer of store host when user is downloading file or not.// in store host header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $file_name); header('Content-Transfer-Encoding: binary'); header('Connection: Keep-Alive'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . $file_size); // readfile($local_file); $c = file_get_contents('ftp://login:pass@download-host.com/uploads/2015/06/app.apk'); echo $c;
I don't want to use bandwidth transfer in store host; Which way can I use? Way 2 or another way?
There's no way to download a contents from the "download host" directly to the client, without providing the client with all the information needed for the download ("download link").
If you need to hide the download information from the client, you need to download the file on the "store host" and then forward it to the client. Hence you are consuming bandwidth data of the "store host". It does not matter what technology, protocol or function you use. And the
ftp_get
andfile_get_contents("ftp://...")
use both the same code behind anyway.Simply said, there's no way to both hide the download information from the client and not use bandwidth data of the "store host".