...

View Full Version : Download remote file and stream to user using cURL



afdah
09-12-2011, 04:04 PM
what this code does is to download a-large-file.zip from example.com and save to hard disk.

instead of saving to hard disk, how do i stream the file to user?



<?php
$url = 'http://www.example.com/a-large-file.zip';
$path = '/path/to/a-large-file.zip';

$fp = fopen($path, 'w');

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);

$data = curl_exec($ch);

curl_close($ch);
fclose($fp);
?>

tangoforce
09-12-2011, 04:11 PM
You still need to save it to the hard disk (otherwise you're in danger of eating up all the ram OR getting a message from php about the memory being exhausted).

Then you need to reopen it and in a loop fread it and print it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum