Importing a file from a URL to my server

Discussion in 'PHP' started by ollyno1uk, Jan 24, 2009.

  1. #1
    Hi there

    I need to download a file from a url and be placed in a folder on my server.


    Can anyone point me n the direction of what I would need to do with php here. I have tried to search on google but I have little to search on that brings any relevant results.

    Any pointers here would be great.

    Thanks a lot
     
    ollyno1uk, Jan 24, 2009 IP
  2. hassanahmad1

    hassanahmad1 Active Member

    Messages:
    150
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    You can use cURL library in php to download a file, like this:
    
    function getFile($url){
      $ch = curl_init();
      curl_setopt($ch,CURLOPT_URL, $url);
      curl_setopt($ch,CURLOPT_FRESH_CONNECT,TRUE);
      //curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
      curl_setopt($ch,CURLOPT_TIMEOUT,180);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
      curl_setopt($ch,CURLOPT_REFERER,'http://www.google.ch/');
      $image=curl_exec($ch);
      if($image==false){
        $m=curl_error(($ch));
        die($m);
      }
      curl_close($ch);
      return $image;
    }
    
    Code (markup):
    But If you have cURL library available then ....
     
    hassanahmad1, Jan 24, 2009 IP
    ollyno1uk likes this.
  3. ollyno1uk

    ollyno1uk Active Member

    Messages:
    946
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    70
    #3
    Thanks a lot for the quick answer. I will try this
     
    ollyno1uk, Jan 24, 2009 IP