Esempio n. 1
0
 public function post()
 {
     $car = new CarModel($_POST['guid']);
     $car->setMake($_POST['make']);
     $car->setModel($_POST['model']);
     $car->setYear($_POST['year']);
     $car->setImage($_POST['image']);
     // Save picture of the car if picture submitted
     if (isset($_FILES['file']) && $_FILES['file']['size'] > 0) {
         // Replace the existing image with a new image of a car
         if (isset($_POST['image']) && !empty($_POST['image'])) {
             parent::deleteFile($_POST['image']);
         }
         parent::saveFile();
         $path = 'uploads/' . $_FILES['file']['name'];
         $car->setImage($path);
         $car->save();
     } else {
         if (isset($_POST['delete'])) {
             // Delete the car and its image
             $car->delete();
             parent::deleteFile($_POST['image']);
         } else {
             $car->save();
         }
     }
     if (headers_sent()) {
         die('Redirect failed. Please go back to home page');
     } else {
         exit(header('Location: index.php'));
     }
 }
Esempio n. 2
0
 public function __construct($post_array = '')
 {
     isset($_POST['guid']) ? $car = new CarModel($_POST['guid']) : ($car = new CarModel());
     $car->setMake($_POST['make']);
     $car->setModel($_POST['model']);
     $car->setYear($_POST['year']);
     isset($_POST['delete']) ? $car->delete() : $car->save();
     if (headers_sent()) {
         die('Redirect failed. Please go back to home page');
     } else {
         exit(header('Location: ./index.php'));
     }
 }