Пример #1
0
 while ($property = mysql_fetch_array($properties_with_roomurl_result)) {
     $roomurl = $property['roomurl'];
     $roomurl = str_replace('http://www.j9accommodation.co.uk/j9/upload/', '', $roomurl);
     $roomurl = str_replace('http://www.exceldiving.co.uk/j9/upload/', '', $roomurl);
     $roomurl_path = $UPLOAD_DIRECTORY . '/' . $roomurl;
     if (!file_exists($roomurl_path) || !is_file($roomurl_path)) {
         // file specified by roomurl column doesnt exist so clear it
         $query = 'UPDATE property SET roomurl = "" WHERE id = "' . $property['id'] . '"';
         $result = mysql_query($query, $db_connection);
         if (!$result) {
             die('Invalid query 1: ' . mysql_error());
         }
         array_push($missing_files, $roomurl_path);
     } else {
         // file exists, so rename it then create thumbnails for it
         $file_name = PhotoManager::generate_file_name($roomurl);
         $file_path = $UPLOAD_DIRECTORY . '/' . $file_name;
         $result = rename($roomurl_path, $UPLOAD_DIRECTORY . '/' . $file_name);
         if (!$result) {
             die('Could not move file');
         }
         $file_name_medium = $pm->_file_name_append($file_name, '-medium');
         $file_medium_contents = $pm->_resize_image($file_path, $pm->THUMBNAIL_MEDIUM_WIDTH, $pm->THUMBNAIL_MEDIUM_HEIGHT);
         $pm->_write_file($file_name_medium, $file_medium_contents);
         $file_name_small = $pm->_file_name_append($file_name, '-small');
         $file_small_contents = $pm->_resize_image($file_path, $pm->THUMBNAIL_SMALL_WIDTH, $pm->THUMBNAIL_SMALL_HEIGHT);
         $pm->_write_file($file_name_small, $file_small_contents);
         // create photo rows
         $property_id = $property['id'];
         $query = "INSERT INTO `photos` (`propertyid`, `filename`, `filename_medium`, `filename_small`, `default`) VALUES \n\t\t\t\t\t\t('{$property_id}', '{$file_name}', '{$file_name_medium}', '{$file_name_small}', 1);";
         $result = mysql_query($query, $db_connection);
Пример #2
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();