Backing up photos with the Raspberry Pi (Part 2)

Back up smartphone pictures

If you have a smartphone or a tablet, you can also upload images to the web server (Figure 4). File uploads are known as a weak spot for hackers to exploit, so make sure you either do this on your local network or take steps to secure your server for remote access.

Figure 4: The Gallery has an upload function if you wish to save pictures from your smartphone.

From a technical point of view, the upload process is quite simple to follow. The PHP page stores the images in a temporary directory, then performs a series of checks. It then moves the photos to the folder /date/uploads which is monitored by systemd. If any new files are found, a custom copy script is launched and the uploaded images are sorted into their respective directories.

Uploads are limited to a maximum of 64 MB in order to prevent the requests from running for too long. You can adjust this limit by changing the values upload_max_filesize and post_max_size in the configuration file /etc/php5/cgi/php.ini.

Wireless Image Bank

To make sure your image bank works while you're on the move, the Raspberry Pi should have its own WiFi network. This works in a similar way to our previous "Do it yourself" article in Raspberry Pi Geek 06/2015, and works in three stages. First, the Raspberry Pi needs a fixed IP address. Next, you need to install a DHCP server on the Raspberry Pi which will respond to requests from other devices for an IP address. Last but not least, you also need the Hostapd daemon which provides the basis for connecting via WiFi.

Listing 4 details your desired network interface configuration in /etc/network/interfaces. The Ethernet connection continues to receive its IP address via DHCP (lines 4 and 5) and thus remains connected to your home network. The WLAN interface has a fixed IP – in this case (lines 7 to 12). You will also need dnsmasq and hostapd, which you already installed by following the steps in Listing 1.

Listing 4


01 auto lo
02 iface lo inet loopback
04 auto eth0
05 iface eth0 inet dhcp
07 auto wlan0
08 iface wlan0 inet static
09 address
10 netmask
11 network
12 broadcast

The file /etc/dnsmasq.conf which is detailed in Listing 5 shows the configuration of the DHCP server referenced in Listing 4. For hostapd you'll have to edit the file /etc/default/hostapd to insert a reference to the configuration file (Listing 6). The configuration file itself can be found in Listing 7. Feel free to change the value wpa_passphrase to a password of your choice.

Listing 5


01 interface=wlan0
02 expand-hosts
04 dhcp-range=,,12h

Listing 6

Insert into /etc/default/hostapd

01 DAEMON_CONF=/etc/hostapd.conf

Listing 7


01 ssid=pi-imgbank
03 ctrl_interface=/var/run/hostapd
04 interface=wlan0
05 driver=nl80211
06 channel=11
08 beacon_int=100
09 hw_mode=g
10 ieee80211n=0
11 wmm_enabled=1
12 ht_capab=[SHORT-GI-20][SHORT-GI-40][HT40-]
14 wpa=2
15 wpa_passphrase=my+pi-imgbank!
16 wpa_key_mgmt=WPA-PSK
17 wpa_pairwise=TKIP
18 rsn_pairwise=CCMP TKIP
19 max_num_sta=8
20 wpa_group_rekey=86400

If you're using a second-generation Raspberry Pi without built-in WiFi, you can use an external WLAN dongle if you make a few tweaks. Take a look at the RPG article referenced below for further help with this. If you don't feel comfortable setting up the hotspot manually, there's also an automatic configuration script for this on the author's GitHub page, located in the /tools directory named install-hostapd.

In addition to the configuration described here, the script also enters the host name and fixed IP address into the /etc/hosts. Since dnsmasq resolves names in this file, you can easily access the images stored on the backup Rasp Pi from a mobile device that is embedded in the WLAN of the Rasp Pi, at the URL http://pi-img/ (our example).

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content