File Uploader |
Top Previous Next |
The File Uploader is a tool to automatically upload photos, animated GIFs and MP4 movies from the photo booth to online galleries. It can upload files using HTTPS POST to a website or an online gallery.
Files are automatically added to the upload queue after each photo booth shooting sequence and are uploaded in the background allowing the photo booth to take the next set of photos without having to wait. If there is no internet connection at the event the files will be held in the queue until an internet connection is available.
General Settings
Select Tools->Uploader to display the settings dialog:
Check the "Upload files" checkbox to enable the uploading of files. When enabled files will be added to the upload queue after each set of photos. The files will be uploaded in the background allowing the photo booth to continue without interruption.
Set the "Upload URL" to call a script on the website where the files will be uploaded. The uploader will use an HTTP POST to upload the files. Then set the password used by the web site to protect it from unauthorized uploads. A sample PHP script to receive the uploaded files is listed below.
Select "Upload XML summary" to upload the photo booth XML summary. The XML summary file contains detailed information, such as survey data, about the session which can be used by some gallery software to provide statistics and analytics.
Select "Upload JPEG copy of printed output" to upload the JPEG copy of the printed output. Please note that the JPEG copy of the printed output is a copy of what is sent to the printer and may include printer margins and both strips if printing double strips in 6x4 media to a printer that cuts the paper into two 6x2 strips. If you want crop the output to remove the printer margins or to only upload a single strip when printing double strips use the "Upload processed copy of the printed output" described below.
Select "Upload processed copy of the printed output" to upload the the processed copy of the printed output. This is useful if you want to crop or resize the printed output before uploading. Please see this section for details on how to create a processed copy of the printed output and to crop and resize it.
Select "Upload email and sharing XML files" to upload the XML files that are saved when sending an email or text. The XML sharing files contain detailed information such as the email address and responses to any input entered in the email or text keyboards.
Select "Upload original photos" to also upload the original photos taken by the camera.
The uploader stores the upload queue in a database on the computer. Set the "Duration to keep records" to the number of days the upload information should be held in the database. Click on the "View uploads..." button to see a summary of the files uploaded, the files in the queue waiting to be uploaded and any errors:
Click on "Clear queues..." to delete the entries from the database. Please note any pending uploads in the upload queue will be discarded.
The PHP script below shows how files sent by DSLR Remote Pro's File Uploader using the HTTPS POST method can be received on a web site. This script is for illustrative purposes only and comes with no warranty or support. You are free to use this script or modify it as required, but if you do so you are responsible for checking that it is secure and meets your requirements.
The script handles two types of request:
<?php
function logError($msg) { file_put_contents('../upload_log.txt', $msg . PHP_EOL, FILE_APPEND | LOCK_EX); }
function fatalError($code, $msg) { // clear the old headers header_remove();
// set the actual code http_response_code($code);
// set the header to make sure cache is forced header("Cache-Control: no-transform,public,max-age=300,s-maxage=900");
header('Content-Type: text/plain; charset=utf-8'); echo $msg; logError($msg); exit(); }
// replace this with a more secure password $password = "photos";
// folder in which to store uploaded images $destdir = "../gallery_uploads";
$id = $_POST["id"]; $request = $_POST["request"]; $filename = $_POST["filename"]; $chksum = $_POST["md5"]; $key = $_POST["key"];
// check client authentication string is correct $localKey = "breeze" . $id . $password . $filename . $chksum; if (sha1($localKey) != $key) { fatalError(401, "Not authorized $key, " . sha1($localKey) . " id=$id, filename=$filename"); }
if ($request == "get_status") { // check whether file already exists on the server $destFile = "$destdir/$filename"; $arr = array('exists' => file_exists($destFile), 'filename' => $filename); fatalError(400, json_encode($arr)); } else if ($request != "upload") { // check whether it is an upload request fatalError(400, "Invalid request: $request"); }
try { // Undefined | Multiple Files | $_FILES Corruption Attack // If this request falls under any of them, treat it invalid. if (!isset($_FILES['fileToUpload']['error']) || is_array($_FILES['fileToUpload']['error'])) { fatalError(400, "Invalid parameters"); }
// Check $_FILES['fileToUpload']['error'] value. switch ($_FILES['fileToUpload']['error']) { case UPLOAD_ERR_OK: break; case UPLOAD_ERR_NO_FILE: fatalError(400, 'No file sent'); case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: fatalError(400, 'Exceeded form file size limit'); default: fatalError(400, 'Unknown error'); }
// Check MIME type $finfo = new finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->file($_FILES['fileToUpload']['tmp_name']); if (false === array_search( $mimeType, array( 'image/jpeg', 'image/gif', 'video/mp4', 'video/quicktime', 'text/xml', ) )) { fatalError(400, "Unexpected MIME type: " . $mimeType); }
$srcFile = $_FILES["fileToUpload"]["tmp_name"];
// check file is JPEG, GIF, MP4 or XML $fileType = strtolower(pathinfo($filename,PATHINFO_EXTENSION)); if ($fileType != "jpg" && $fileType != "gif" && $fileType != "mp4" && $fileType != "xml" ) { fatalError(400, "File type not allowed"); }
// check MD5 checksum matches uploaded file if (strcasecmp(md5_file($_FILES["fileToUpload"]["tmp_name"]), $chksum) != 0) { fatalError(400, "MD5 checksum incorrect"); }
// read filename and dir from $filename and create dir if it doesn't already exist [ 'basename' => $basename, 'dirname' => $dirname ] = pathinfo($filename); $destFile = "$destdir/$basename"; if (strlen($dirname) > 0) { $dir = "$destdir/$dirname"; if (!file_exists($dir)) { mkdir($dir, 0777, true); } if (file_exists($dir)) { $destFile = "$dir/$basename"; } }
// move the uploaded file to the upload folder if (move_uploaded_file($srcFile, $destFile)) { header('Content-Type: text/plain; charset=utf-8'); echo "File: $destFile"; } else { logError("move_uploaded_file($srcFile, $destFile) failed"); fatalError(400, "Error copying file to upload folder: $destFile"); } } catch (RuntimeException $e) { fatalError(400, $e->getMessage()); }
?>
|