Strict Standards: Declaration of blogRouter::parseRoute() should be compatible with birdyRouteHelper::parseRoute($queryParts, $possible = Array) in /home/chrismic/public_html/templates/Diverso/routers/blog.php on line 7
Download a file with cURL

Warning: mb_detect_encoding() expects parameter 1 to be string, array given in /home/chrismic/public_html/birdy/db.php on line 19

Warning: mb_detect_encoding() expects parameter 1 to be string, array given in /home/chrismic/public_html/birdy/db.php on line 19

by


Warning: mb_detect_encoding() expects parameter 1 to be string, array given in /home/chrismic/public_html/birdy/db.php on line 19

In: Web Development

No Comments

In many situations you want to download a file (or a page) from another server to your server. You can do this with cURL! Here is a function which does that, written in PHP.

<?php
function downloadFile($url, $path='', $file='', $options = array())
  {
    //make sure the options is an array
    if (!is_array($options)) $options = array();
    //add default options. You can remove these from here, but make sure you give the options you removed, when you call this method
    $options = array_merge(array(
        'connectionTimeout' => 5, // seconds
        'timeout' => 10, // seconds
        'sslVerifyPeer' => false,
        'followLocation' => false, // if true, limit recursive redirection by
        'maxRedirs' => 1, // setting value for "maxRedirs"
          ), $options
            );
        
    // if no filename given, create a random filename (with no extension)
    if (empty($filename)) $filename = rand();
    // create a file (we are assuming that we can write to the system's directory)
    $FileName = $path.$filename;
    $fh = fopen($FileName, 'w');

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_FILE, $fh);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $options['connectionTimeout']);
    curl_setopt($curl, CURLOPT_TIMEOUT, $options['timeout']);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $options['sslVerifyPeer']);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, $options['followLocation']);
    curl_setopt($curl, CURLOPT_MAXREDIRS, $options['maxRedirs']);
    curl_exec($curl);

    curl_close($curl);
    fclose($fh);

    return $FileName;
  }
?>


Strict Standards: Non-static method birdyComments::submitComment() should not be called statically in /home/chrismic/public_html/birdy/helpers/comments/inc_rate.php on line 166

Warning: mb_detect_encoding() expects parameter 1 to be string, array given in /home/chrismic/public_html/birdy/db.php on line 19

Leave a Reply   

The Sinner In Me (Chris Vulture Mix) by Chris Vulture on Mixcloud