Joomla Extensions by Roalcana

Download a file and save it locally with cURL

( 48 Votes ) 

A fragment of code that will help you to download a file from anywhere in the web and to save it locally in your webserver.

    # Set your own path and filename
    $localFile  = '/home/any/path/filename.txt';
    # Set the URI for the file to download
    $remoteFile = 'http://www.elwebserver.com/path/to/file.txt';
    if ($fp = @fopen ($localFile, 'w+'))
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $remoteFile);
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_exec($ch);
        if(curl_errno($ch))
        {
            echo 'ERROR: ' . curl_error($ch);
        }
        curl_close($ch);
        fclose($fp);
    }
You are here: Home Blog Download a file and save it locally with cURL

Connect With Us

Trademark Disclaimer

Product names, logos, brands, and other trademarks referred to within roalcana.com are the property of their respective trademark holders. These trademark holders are not affiliated with Roalcana, our products nor our website. They do not sponsor or endorse any of our solutions.