Download a Remote File Using PHP and cURL

by damonp on February 3, 2011

in PHP,Snippets

Some years back, I posted a function to download a remote file with PHP. The function was useful when cURL and other URL/remote file functions had been disabled for security reasons. At the time, cURL on PHP was relatively new and many hosting setups didn’t include the cURL PHP module.

Support for PHP-cURL is pretty standard now, so I thought I’d update the the function to use cURL now. In addition, the function no longer returns a buffer containing the file data which can cause memory issues in PHP when dealing with large files. Pass this updated function a remote URL and local file path and it will download the file and save it to the local path.

This function is useful to retrieve remote images, download HTML pages and download any remote files.

    function http_get_file($remote_url, $local_file)    {
        $fp = fopen($local_file, 'w');
        $cp = curl_init($remote_url);
        curl_setopt($cp, CURLOPT_FILE, $fp);
        $buffer = curl_exec($cp);
        return true;


Hardcode WordPress Site URL

by damonp on January 11, 2011

in Snippets

I’m working on a project for mobile devices and need to be able to setup the same WordPress install on both the .mobi and the .com domain. This snippet lets you hardcode the URL and home configurables in wp_config.php. We use one setup of configurables for the .mobi side and another set for the .com.


Thanks to the WordPress Codex.


Linux Grep Tips

17 November 2010

Search for red OR green: grep ‘red\|green’ files Search for searchtext at the beginning of a line in files: grep ‘^searchtext’ files Search for searchtext at the end of a line in files: grep ‘searchtext$’ files Search files for blank lines: grep ‘^$’ files Search files for US formatted phone numbers (###-###-####): grep ‘[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]’ files […]

Read the full article →

HTML Image Caption

10 November 2010

<div id="image-caption"><img style="border: 1px solid black; float: right; margin: 0 0 10px 10px;" src="/images/imagename.jpg" border="0" alt="" width="175" height="132" /> <p class="caption">HTML Image Caption</p> </div> <!– #image-caption { position: relative; } #image-caption p.caption { text-align:center; position: relative; bottom: 0px; left: 0px; margin: 0; padding: 5px 3%; background-color: #555; color: #fff; font-weight: bold; font-size:.75em; } –>

Read the full article →

Cannot find terminfo entry for ‘xterm-256color’

10 November 2010

Check if you have the terminfo file installed. find /lib/terminfo /usr/share/terminfo -name "*256*" No results? Install ncurses-term. sudo apt-get install ncurses-term

Read the full article →

Debugging Wifi Connectivity and Routing

12 June 2010

Sometimes wifi connectivity issues can be massaged a little by getting a little pushy with it… turn your internal airport card off. Leave it off for a minute then turn it back on and see if by forcing it to attempt to re-connect to your local network.  Oftentimes this will clear up minor issues. Check […]

Read the full article →

Cloudy Costa Rican Sunset

2 June 2010

Looks like it’s going to rain tonight.

Read the full article →

iPhone Goodreader and Email

28 April 2010

Goodreader is simply the best PDF / document reader around for the iPad. It allows you to download documents in a dozen different ways and store them locally on your device. Another great feature is the ability to directly email these as attachments from inside Goodreader. Unfortunately, said feature is limited somewhat by the limitations […]

Read the full article →

Enable Sendmail for PHP mail() in OSX

25 February 2010

Since this didn’t dawn on me for thirty minutes while I pursued other avenues… In /etc/hostconfig add/edit a line like: MAILSERVER=-YES- Note to self: Look for more OSX server administration clients.

Read the full article →

Apache Log Grepping

14 September 2009

Nothing beats a full stats package, but with a little grepping and a logfile and we can figure out some quick statistics. Get only hits coming from grep ‘’ access_log | head -1 Extract only the referrer field: grep ‘’ access_log | head -1 | awk ‘{print $11}’ Get the search terms only: grep […]

Read the full article →