Downloading a Remote File With cURL and PHP

Posted by midhun pottmmal On Friday, 21 December 2012 0 comments

         cURL is a great tool to help you connect to remote web sites, making it easy to post forms, retrieve web pages, or even to download files (e.g if you want to use a web-based API, provided by service like TinyURL, Digg, Twitter) ,actually it is  very simple and faster to use than other methods of downloading .



The simplest code of a PHP function to retrieve file’s contents using PHP’s CURL is below:


function getfile($url)
{
                   // More great PHP snippets at http://www.scriptime.blogspot.in
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
        $downloaded = curl_exec($ch);
        curl_close($ch);
        return $downloaded;
 }       

try this code :-
$contents = getfile("http://scriptime.blogspot.in/feeds/posts/default")


0 comments:

Post a Comment

Fashion