// fetch from amazon $fetch_url = ImgStore::getUrl($image['image_id'], $image['size_id'], 0); $real_private_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id'], $private = true); log_('fetching ' . $fetch_url . ' to ' . $real_private_path); file_put_contents($real_private_path, file_get_contents($fetch_url)); log_($image['bytes'] . '=db size,' . filesize($real_private_path) . '=real size copied'); 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'); } }