// get originals $query = 'SELECT * FROM `images` WHERE `is_orig`=1 AND `image_id` IN(' . implode(',', $image_ids) . ')'; $originals = Database::sql2array($query, 'image_id'); foreach ($tasks as $task) { echo "\n"; if (isset($originals[$task['image_id']])) { $or = $originals[$task['image_id']]; $orig_file_path = ImgStore::getFileLocalPath($or['image_id'], $or['size_id']); log_('task#' . $task['id'] . ' original imageid#' . $or['image_id'] . ' ' . $or['width'] . 'x' . $or['height'] . ', ' . round($or['bytes'] / 1024 / 1024 * 1000) / 1000 . ' Mb'); if (!is_readable($orig_file_path)) { $to_delete[$task['id']] = $task['id']; $to_error[$task['id']] = ImgStore::ERROR_NOT_READABLE; log_($orig_file_path . ' is not readable'); } else { log_($orig_file_path . ' is readable, processing to ' . $task['width_requested'] . 'x' . $task['height_requested']); $target_file_path = ImgStore::getFileLocalPath($task['image_id'], $task['size_id']); $settings = array('width' => $or['width'], 'height' => $or['height'], 'crop_method' => $task['crop_method'], 'width_requested' => $task['width_requested'], 'height_requested' => $task['height_requested'], 'size_id' => $task['size_id']); log_('saving to ' . $target_file_path); list($new_width, $new_height, $target_width, $target_height) = ImgStore::resize($orig_file_path, $settings, $target_file_path); $bytes = filesize($target_file_path); log_('saved as ' . $new_width . 'x' . $new_height . '[requested ' . $target_width . 'x' . $target_height . '], ' . round($bytes / 1024 / 1024 * 1000) / 1000 . ' Mb'); Database::query('UPDATE `images` SET `width`=' . $new_width . ', `height`=' . $new_height . ', `ready`=1, `server_id`=' . ImgStore::SERVER_ORIG . ', `bytes` =' . $bytes . ' WHERE `id`=' . $task['id']); } } else { log_('task# ' . $task['id'] . ' original missed!'); $to_delete[$task['id']] = $task['id'];
if (filesize($real_private_path)) { $amazon_dest = str_replace(ImgStore::$server_urls[ImgStore::SERVER_AMAZONS3], '', $fetch_url); $res = Amazon::delete($amazon_dest); log_('deleted ' . $amazon_dest . ' from amazon with code:' . $res); Database::query('UPDATE `images` SET `server_id`=' . ImgStore::SERVER_PRIVATE . ', `private_real`=1 WHERE `id`=' . $image['id']); } } else { // get from local file, delete amazon copy $amazon_dest = str_replace(ImgStore::$server_urls[ImgStore::SERVER_AMAZONS3], '', ImgStore::getUrl($image['image_id'], $image['size_id'], 0)); $res = Amazon::delete($amazon_dest); log_('deleted ' . $amazon_dest . ' from amazon with code:' . $res); // $real_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id']); log_($image['id'] . ' at original server in ' . $real_path . ' ' . filesize($real_path) . ' bytes'); // change location to private folder $real_private_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id'], $private = true); log_('will be moved to ' . $real_private_path); if (copy($real_path, $real_private_path)) { log_('succesfully copied'); Database::query('UPDATE `images` SET `server_id`=' . ImgStore::SERVER_PRIVATE . ', `private_real`=1 WHERE `id`=' . $image['id']); unlink($real_path); } else { log_('cant copy'); } } } } } } function log_($txt) {
<?php ini_set('display_errors', 1); $end = array_pop(explode('/', $_SERVER['REQUEST_URI'])); list($image_id, $size) = explode('-', $end); $image_id = (int) $image_id; $size = (int) $size; if ($image_id) { $core_path = 'core/'; require_once $core_path . 'config.php'; require_once $core_path . 'include.php'; $authorized = CurrentUser::authorize_cookie(); if ($authorized) { $owner = Database::sql2single('SELECT `creator_id` FROM `album_events` WHERE `picture`=' . $image_id); if ($owner == CurrentUser::$id) { header('Content-type: image/jpeg'); header('Content-Disposition: inline; filename=protected_' . $image_id . '-' . $size . '.jpg'); header('X-Accel-Redirect: /images_private/' . str_replace(ImgStore::ROOT_PRIVATE_FOLDER, '', ImgStore::getFileLocalPath($image_id, $size, $private = true))); exit(0); } else { die('Изображение является приватным и доступно только владельцу'); } } else { die('Изображение является приватным и доступно только владельцу'); } }
exit(0); } foreach ($to_export as $image) { if ($limit['uploaded_bytes'] > $day_limit_bytes) { log_('LIMIT REACHED[BYTES]:' . $limit['uploaded_bytes'] . ' FROM ' . $day_limit_bytes); exit(0); } else { log_('LIMIT [BYTES]:' . $limit['uploaded_bytes'] . ' FROM ' . $day_limit_bytes); } if ($limit['uploaded_count'] > $day_limit_count) { log_('LIMIT REACHED[COUNT]:' . $limit['uploaded_count'] . ' FROM ' . $day_limit_count); exit(0); } else { log_('LIMIT [COUNT]:' . $limit['uploaded_count'] . ' FROM ' . $day_limit_count); } $real_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id']); log_($real_path . ' ' . floor($image['bytes'] / 1024 / 1024 * 1000) / 1000 . 'Mb'); $target_path = str_replace(ImgStore::$server_urls[ImgStore::SERVER_ORIG], '', ImgStore::getUrl($image['image_id'], $image['size_id'], 0)); log_('saving to ' . $target_path); $result = Amazon::store($real_path, $target_path); if ($result) { $limit['uploaded_count']++; $limit['uploaded_bytes'] += $image['bytes']; log_('Stored at amazon at ' . ImgStore::$server_urls[ImgStore::SERVER_AMAZONS3] . $target_path); Database::query('UPDATE `images` SET `server_id`=' . ImgStore::SERVER_AMAZONS3 . ', `amazon_stored_time`=' . time() . ' WHERE `id`=' . $image['id']); } else { log_('Cant store file to amazon'); Database::query('UPDATE `images` SET `amazon_stored_time`=' . time() . ' WHERE `id`=' . $image['id']); }