Showing posts with label CURL. Show all posts
Showing posts with label CURL. Show all posts

10 December, 2009

DOWNLOAD FILE USING PHP

You can easily download file in your server using PHP.

You can use PHP's  copy() function or file_get_contents() and file_put_contents() functions or curl library to download file.

Here is some example for you :
COPY FUNCTION

  1. $file = "http://example.com/file.html";
  2. copy($file,"eshan.html"); 
file_get_contents and file_fut_contents
  1.   $file = "http://example.com/file.html";
  2. $file_data = file_get_contents($file); 
  3. file_put_contents("eshan.html",$file_data)
CURL
  1. $ch = curl_init($file);
  2. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  3. curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
  4. $data = curl_exec($ch);
  5. $fp = fopen("dpt.php","w");
  6. fwrite($fp,$data);
ENJOY !!!