Posted By

Frank on 04/28/08


Tagged

curl php server FTP


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

crs0328
dryliketoast
jamesming
rinx


cURL in PHP


 / Published in: PHP
 

URL: www.nightofthedrums.com

This can save your life if you need 2 servers to have the same data with 1 upload

  1. /**
  2.  * cURL file copy to another server
  3.  * This file saved my life when i had to let a file upload synchrom to a different server, no ftp messing around!
  4.  */
  5. $rCurl = curl_init();
  6.  
  7. /**
  8.  * The file to copy
  9.  */
  10. curl_setopt($rCurl, CURLOPT_URL, 'http://www.google.nl/intl/nl_nl/images/logo.gif');
  11.  
  12. /**
  13.  * cURL options dunno what for
  14.  */
  15. curl_setopt($rCurl, CURLOPT_HEADER, false);
  16.  
  17. /**
  18.  * cURL options dunno what for
  19.  */
  20. curl_setopt($rCurl, CURLOPT_BINARYTRANSFER, true);
  21.  
  22. /**
  23.  * cURL options dunno what for
  24.  */
  25. curl_setopt($rCurl, CURLOPT_RETURNTRANSFER, true);
  26.  
  27.  
  28. /**
  29.  * The php file limit
  30.  */
  31.  
  32. /**
  33.  * set cURL timeout
  34.  */
  35. curl_setopt($rCurl, CURLOPT_TIMEOUT, 300);
  36.  
  37.  
  38. /**
  39.  * The file that will be written
  40.  */
  41. $rOutPut = fopen('googlelogo.gif', 'wb');
  42.  
  43. /**
  44.  * Setup the transfer ?
  45.  */
  46. curl_setopt($rCurl, CURLOPT_FILE, $outfile);
  47.  
  48.  
  49. /**
  50.  * Execute the transfer
  51.  */
  52. curl_exec($rCurl);
  53.  
  54. /**
  55.  * Close the file
  56.  */
  57. fclose($rOutPut);
  58.  
  59.  
  60. /**
  61.  * Close cURL
  62.  */
  63. curl_close($rCurl);

Report this snippet  

You need to login to post a comment.