Juno_okyo

Download a file using curl in php

Jan 27th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. <?php
  2. set_time_limit(0);
  3.  
  4. //File to save the contents to
  5. $fp = fopen ('files2.tar', 'w+');
  6.  
  7. $url = "http://localhost/files.tar";
  8.  
  9. //Here is the file we are downloading, replace spaces with %20
  10. $ch = curl_init(str_replace(" ","%20",$url));
  11.  
  12. curl_setopt($ch, CURLOPT_TIMEOUT, 50);
  13.  
  14. //give curl the file pointer so that it can write to it
  15. curl_setopt($ch, CURLOPT_FILE, $fp);
  16. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  17.  
  18. $data = curl_exec($ch);//get curl response
  19.  
  20. //done
  21. curl_close($ch);
Add Comment
Please, Sign In to add comment