Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
09-12-2011, 04:04 PM #1
- Join Date
- Aug 2011
- Thanked 0 Times in 0 Posts
Download remote file and stream to user using cURL
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?
$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);
09-12-2011, 04:11 PM #2
- Join Date
- Feb 2011
- Your Monitor
- Thanked 525 Times in 512 Posts
- Blog Entries
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.
See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/
Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!