Esempio n. 1
0
 function actionSave()
 {
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         throw new MyException('Вы не туда попали.');
     }
     if (empty($_POST['title'])) {
         throw new MyException('Поле "Заголовок" - обязательное!');
     }
     if ($_FILES['img']['name']) {
         $types = array('image/gif', 'image/png', 'image/jpeg');
         $size = 10000000;
         if (!in_array($_FILES['img']['type'], $types)) {
             throw new MyException('Мы такие форматы не грузим.');
         }
         if ($_FILES['img']['size'] > $size) {
             throw new MyException('Слишком большой размер картинки.');
         }
         $image = file_get_contents($_FILES['img']['tmp_name']);
     }
     $obj = new ObjectModel();
     $obj->title = $_POST['title'];
     $obj->text = $_POST['text'];
     $obj->type = $_POST['type'];
     $obj->img = $image ? $image : null;
     $obj->insert();
     header("Location: http://work/objectForDB/");
     exit;
 }