Example #1
0
 /**
  * Handle incoming upload requests, i.e. save meta data in
  * database and store payload on disk.
  */
 public static function handleUploadRequest($latitude, $longitude, $title, $timestamp, $description, $payloadType, $payload)
 {
     // Validate geo coordinates
     if (!MediaServer::validGeoCoordinates($latitude, $longitude)) {
         return array('Statuscode' => 'Error', 'Message' => 'Invalid or no geo coordinates provided.');
     }
     // Validate payload type
     if (!MediaServer::validatePayloadType($payloadType)) {
         return array('Statuscode' => 'Error', 'Message' => 'Invalid or no payload type provided.');
     }
     // Generate random file name
     $sampleID = MediaServer::generateSampleID($latitude, $longitude, $title, $timestamp, $description);
     // Write file to disk
     if (!MediaServer::storePayload($sampleID, $payload)) {
         return array('Statuscode' => 'Error', 'Message' => 'Could not store payload on disk.');
     }
     // Save meta data in database
     $database = new Database();
     if (!$database->saveMetadata($latitude, $longitude, $title, $timestamp, $description, $sampleID, $payloadType)) {
         MediaServer::deleteFile($sampleID);
         // Remove payload from disk
         return array('Statuscode' => 'Error', 'Message' => 'Could not write meta data to database.');
     }
     // Log file upload
     Logger::log('File uploaded (Title: \'' . $title . '\', Sample ID: \'' . $sampleID . '\'): ' . 'http://maps.google.com/maps?q=' . $latitude . '+' . $longitude, Logger::SAMPLE_UPLOAD);
     // Send response
     return array('Statuscode' => 'OK', 'Message' => 'Media file uploaded successfully.', 'SampleID' => $sampleID);
 }