Exemple #1
0
* limit in php.ini, so we validate $_SERVER['CONTENT_LENGTH'] to avoid unnecessary
* warnings and to make overall experience a bit more user friendly
**/
$postMaxSize = Info::convertToBytes(ini_get('post_max_size'));
if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > $postMaxSize) {
    Session::flash('home', 'Вы пытаетесь загрузить слишком большой файл.');
    Redirect::to();
}
$errorHandler = new ErrorHandler();
if (Input::exists()) {
    if (Token::check(Input::get('token'))) {
        /*==================================
          =            Validation            =
          ==================================*/
        if (empty($_FILES) === false) {
            $fileValidator = new ValidateFile($errorHandler);
            $fileValidator->check($_FILES, ['cover' => ['sizeAllowed' => Config::get('upload_book_cover/max_file_size'), 'typeAllowed' => Config::csvToArray(Config::get('upload_book_cover/mime_types')), 'extensionAllowed' => Config::csvToArray(Config::get('upload_book_cover/extensions')), 'isImage' => true]]);
        }
        $validator = new Validate($errorHandler);
        $validator->check($_POST, ['author' => ['required' => true, 'minLength' => 3, 'partMinLength' => [3, ','], 'maxLength' => 240, 'partMaxLength' => [60, ',']], 'title' => ['required' => true, 'minLength' => 3, 'maxLength' => 80], 'title_secondary' => ['minLength' => 3, 'maxLength' => 80], 'genre' => ['required' => true, 'minLength' => 4, 'partMinLength' => [4, ','], 'maxLength' => 120, 'partMaxLength' => [30, ',']], 'publisher' => ['minLength' => 3, 'partMinLength' => [3, ','], 'maxLength' => 100, 'partMaxLength' => [50, ',']], 'year' => ['required' => true, 'digit' => true, 'exactLength' => 4], 'isbn' => ['required' => true, 'minLength' => 10, 'partMinLength' => [10, ','], 'maxLength' => 36, 'partMaxLength' => [17, ',']], 'pages' => ['digit' => true, 'minLength' => 2, 'maxLength' => 4], 'dimensions' => ['minLength' => 5, 'maxLength' => 10], 'price' => ['price' => true, 'minLength' => 2, 'maxLength' => 7]]);
        /*=====================================
          =            Book creation            =
          =====================================*/
        if ($errorHandler->hasErrors() === false) {
            $bookManager = new BookManage();
            $data = ['author' => Input::get('author'), 'title' => Input::get('title'), 'title_secondary' => Input::get('title_secondary'), 'description' => Input::get('description'), 'genre' => strtolower(Input::get('genre')), 'publisher' => Input::get('publisher'), 'year' => Input::get('year'), 'isbn' => Input::get('isbn'), 'pages' => Input::get('pages'), 'dimensions' => Input::get('dimensions'), 'price' => Input::get('price')];
            $bookManager->update($data, $book->id);
            $message = 'Информация о книге(' . $book->title . ', ' . $book->id . ') была отредактирована.';
            Log::getInstance()->message($message, 'book_manage');
            if (empty($_FILES) === false) {
                $upload = new UploadBookCover($fileValidator, $book->id);
Exemple #2
0
 /**
  * Requires data from validation class to avoid the need of reforming $_FILES array twice
  * @param object of type ValidateFile $validator
  * @return object
  */
 public function __construct(ValidateFile $validator)
 {
     $this->input = $validator->getInput();
 }