File Uploader

The File Uploader automatically uploads photos, animated GIFs, and MP4 movies from the photo booth to an online gallery or website using HTTPS POST. Files are added to an upload queue after each shooting sequence and uploaded in the background, so the booth can continue taking photos without waiting. If there is no internet connection, files are held in the queue until connectivity is restored.

 

Setup

Open the settings via Tools -> Uploader.

 

  • Upload files — enables the uploader
  • Upload URL — the URL of the script on your web server that receives the files
  • Password — used by the web server to verify uploads
  • Upload XML summary — uploads the XML shooting summary file (includes survey data and analytics)
  • Upload JPEG copy of printed output — uploads the direct JPEG print copy
  • Upload processed copy of the printed output — uploads a cropped or resized version of the print (see Output Settings for how to create a processed copy)
  • Upload email and sharing XML files — uploads the XML files saved when sending emails or texts
  • Upload original photos — uploads the original camera photos
  • Upload processed photos — uploads the processed versions of photos

Set Duration to keep records to control how long upload history is held in the database. Click View uploads… to see queued and completed uploads, plus any errors.

 

Click Clear queues… to remove entries from the database. Pending uploads in the queue will be discarded.

 

Sample PHP Script

The PHP script below provides a starting point for receiving uploaded files on your web server. It handles two request types:

  • get_status — checks whether a file already exists on the server
  • upload — receives and saves the uploaded file

The script validates the file type (JPEG, GIF, MP4, XML), checks the MD5 checksum, verifies the authentication key, and saves the file to a destination folder. Adapt it to your own requirements.


<?php
function logError($msg)
{
    file_put_contents('../upload_log.txt', $msg . PHP_EOL, FILE_APPEND | LOCK_EX);
}
function fatalError($code, $msg)
{
    header_remove();
    http_response_code($code);
    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();
}
$password = "photos";
$destdir = "../gallery_uploads";
$id = $_POST["id"];
$request = $_POST["request"];
$filename = $_POST["filename"];
$chksum = $_POST["md5"];
$key = $_POST["key"];
$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")
{
    $destFile = "$destdir/$filename";
    $arr = array('exists' => file_exists($destFile), 'filename' => $filename);
    fatalError(400, json_encode($arr));
}
else if ($request != "upload")
{
    fatalError(400, "Invalid request: $request");
}
try {
    if (!isset($_FILES['fileToUpload']['error']) || is_array($_FILES['fileToUpload']['error'])) {
        fatalError(400, "Invalid parameters");
    }
    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');
    }
    $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"];
    $fileType = strtolower(pathinfo($filename,PATHINFO_EXTENSION));
    if ($fileType != "jpg" && $fileType != "gif"  && $fileType != "mp4" && $fileType != "xml" ) {
        fatalError(400, "File type not allowed");
    }
    if (strcasecmp(md5_file($_FILES["fileToUpload"]["tmp_name"]), $chksum) != 0) {
        fatalError(400, "MD5 checksum incorrect");
    }
    [ '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";
        }
    }
    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());
}
?>

.p