Save Image to Web with Processing and PHP

Processing demo code that shows how to upload an image from Processing to a web server. It takes a picture with your webcam and saves the image to a folder on your webserver with PHP.

For certain interactive installations (like the Sky Radio Photo booth) I need to be able to save and upload images to a webserver. There are different examples in the Processing forum, but not one clear and easy solution. 

Actually the code is largely based on my Processing Azure Face API code, however instead of sending the image to Microsoft Azure, the image is uploaded to a web server and stored with PHP. Like the Azure example this code uses the Apache HTTP client library (from the Apache HTTPComponents project). It’s already included in the sketch folder, so you don’t have to download or install it separately. 

Get the code on Github

Web Server configuration

First make sure you have a host that supports PHP. 

Create a folder called “processing_upload” on the location you want (or modify the $targetDir variable in saveImage.php). Place saveImage.php in the same folder as you’ve placed the processing_upload folder (pay attention don’t place saveImage.php within processing_upload).

Don’t forget to set the file permissions of the folder to write (755).

Modify the Processing sketch

In the Processing sketch you have to point the String baseUrl  (in ImageUploader.pde) to the folder on your own server where you saved the saveImage.php file. 

Credits