Portal Home > Knowledgebase > Articles Database > Remote File Downloading with PHP + CURL

Remote File Downloading with PHP + CURL

Posted by latheesan, 01-04-2011, 04:43 PM
Hi, I have a file on www.site1.com/file.zip. Is it possible to download that file from www.site2.com/index.php (for example) and send the download straight to the browser? If this is possible, let's say the file.zip is about 10mb. where will the bandwidth be used? on site1.com or site2.com or both? Any links / tutorial page (or even sample code) would be much appreciated.

Posted by Evilzebra, 01-04-2011, 05:06 PM
Well you could probably just do a readfile() and then output the contents. And if you did do that I believe the bandwidth would mostly be on site1 because it has to read the file from there.

Posted by latheesan, 01-04-2011, 05:57 PM
doesn't readfile() download the file to site2 and then serves it?

Posted by cselzer, 01-04-2011, 06:37 PM
Bandwidth would be used on both... unless you use some type of client side way to serve it on site2.

Posted by kjsrs, 01-04-2011, 07:36 PM
In your example, www.site1.com will use outbound bandwidth to send the file to www.site2.com. www.site2.com will use incoming bandwidth to receive the file, then the same amount of outbound bandwidth to send to the browser. There are definitely ways to cache the file on www.site2.com so it only has to send it to the browser, and not download it each time.

Posted by Evilzebra, 01-04-2011, 11:13 PM
Definitely meant site 2 on that, but the others are right, I kinda forgot about that. But couldn't you just use a .htaccess redirect? For example: RewriteRule ^/?file/([0-9]+).zip$ http:[slash][slash]www[dot]site1[dot]com/file/$1.zip Can't "link to URL's" because I'm a new user, replaces [dot] with . and [slash] with /

Posted by latheesan, 01-05-2011, 08:03 AM
Thanks for the info guys, much appreciated.

Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read