Example #1
0
<?php

require_once 'ApiResponses.php';
require_once '../config.php';
if (!array_key_exists('property_id', $_POST) || !array_key_exists('file_contents', $_POST) || !array_key_exists('file_name', $_POST)) {
    $response = new ApiResponseFailure('Missing one of the following: file_contents, file_name, property_id');
    $response->render();
}
// get file contents and other data
$file_contents = explode(",", $_POST['file_contents']);
$file_contents = $file_contents[1];
$file_contents = str_replace(' ', '+', $file_contents);
$file_contents = base64_decode($file_contents);
$file_name = $_POST['file_name'];
$property_id = $_POST['property_id'];
// add the photo
require_once '../connect.php';
require_once '../PhotoManager.php';
$pm = new PhotoManager($db_connection, $UPLOAD_DIRECTORY);
$file_name = PhotoManager::generate_file_name($file_name);
$written_files = $pm->add_photo($file_name, $file_contents, $property_id);
$response = new ApiResponseFileUploaded($written_files['photo_id'], $written_files['file_name'], $written_files['file_name_medium'], $written_files['file_name_small']);
$response->render();