Say I go to http://example.com/dynamic.php?file=content&ext=wav The dynamic.php script forces the browser to download it but I want to cache the file using php.
Here is what I have so far
Code: Select all
$file = './content.wav'; // What I want the file to be downloaded as.
$remote_url = 'http://example.com/dynamic.php?file=content&ext=wav';
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $remote_url);
curl_setopt($handle, CURLOPT_TIMEOUT, 3);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($handle);
$fhandle = fopen($file, 'w+');
fwrite($fhandle, $output);
fclose($fhandle);
curl_close($handle);