Bnaya

PHP download proxy

Dec 9th, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2. set_time_limit(0);
  3. $url = 'http://mirror.isoc.org.il/pub/fedora/releases/17/Live/x86_64/Fedora-17-x86_64-Live-Desktop.iso';
  4. $file_name = 'Fedora-17-x86_64-Live-Desktop.iso';
  5. header('Content-Type: application/octet-stream');
  6. header("Content-Disposition: attachment; filename=" . $file_name);
  7. ob_end_flush();
  8.  
  9. // Headers function
  10. // You should able to send from here also the content length header with the data from the headers param but its not working as expected ATM
  11. function handle_headers($ch, $headers) {
  12.     return strlen($headers);
  13. }
  14.  
  15. // Output function
  16. function output_chunk($ch, $data) {
  17.     echo $data;
  18.     flush();
  19.     return strlen($data);
  20. }
  21.  
  22.  
  23. $ch = curl_init($url);
  24. curl_setopt_array($ch, array(
  25.     // CURLOPT_HEADERFUNCTION => 'handle_headers',
  26.     CURLOPT_WRITEFUNCTION => 'output_chunk',
  27.     // CURLOPT_RETURNTRANSFER => true,
  28.     // 1 MB
  29.     CURLOPT_BUFFERSIZE => 500000,
  30.     CURLOPT_HEADER => false
  31. ));
  32.  
  33. curl_exec($ch);
Add Comment
Please, Sign In to add comment