Exemple #1
0
})->name('new_lot');
// POST нового лота
$app->post('/lot_post', function () use($app) {
    $data = $app->request->post();
    if (!isset($data['status'])) {
        $data['status'] = UNPUBLISHED;
    }
    if (!isset($data['rent'])) {
        $data['rent'] = 0;
    }
    unset($data['preview']);
    try {
        if ($data['title'] == '') {
            throw new ErrorException('Поле "название" обязательно!');
        }
        $new_lot = Lot::post($data);
        $id = $new_lot->id;
        if (isset($_FILES['preview'])) {
            // загружаем превью
            if ($_FILES['preview']['size']) {
                $preview_file = $_FILES['preview'];
                list($name, $ext) = explode('.', $preview_file['name']);
                $filename = 'orig_' . $id . '.' . $ext;
                $thumb_name = 'thumb_' . $id . '.' . $ext;
                $upload_dir = $app->config('upload.path');
                $file_path = $upload_dir . '/' . $filename;
                $thumb_path = $upload_dir . '/' . $thumb_name;
                if (move_uploaded_file($preview_file['tmp_name'], $file_path) === true) {
                    $imagine = new Imagine\Gd\Imagine();
                    $size = new Imagine\Image\Box(500, 500);
                    $mode = Imagine\Image\ImageInterface::THUMBNAIL_INSET;