Ejemplo n.º 1
0
 public function add_homeimage()
 {
     $this->_checkPermission();
     $data = $_POST['homeimage'];
     Flash::set('postdata', $data);
     $image = $_POST['upload'];
     $path = str_replace('..', '', $image['path']);
     $path2 = str_replace('..', '', $image['path2']);
     $overwrite = false;
     // verification
     if (empty($data['title'])) {
         Flash::set('error', __('You have to specify a homeimage title!'));
         redirect(get_url('homeimage/create'));
     }
     // if (empty($data['url'])){
     // 	Flash::set('error', __('You have to specify the URL!'));
     // 	redirect(get_url('homeimage/create'));
     // }
     if (isset($_FILES)) {
         // no image file selected
         if (empty($_FILES['upload_file']['name'])) {
             Flash::set('error', __('You have to select a image to be uploaded!'));
             redirect(get_url('homeimage/create'));
         }
     } else {
         Flash::set('error', __('You have to select a image to be uploaded!'));
         redirect(get_url('homeimage/create'));
     }
     $homeimage = new HomeImage($data);
     $homeimage->created_by_id = AuthUser::getId();
     $homeimage->created_on = date('Y-m-d H:i:s');
     if (!$homeimage->save()) {
         Flash::set('error', __('Home Image is not added!'));
         redirect(get_url('homeimage/create'));
     } else {
         if (isset($_FILES)) {
             $homeimage_id = $homeimage->lastInsertId();
             $file = $this->upload_file($_FILES['upload_file']['name'], FILES_DIR . '/homeimage/images/', $_FILES['upload_file']['tmp_name'], $overwrite, $homeimage_id);
             $file_hover = $this->upload_file($_FILES['upload_file_hover']['name'], FILES_DIR . '/homeimage/images/', $_FILES['upload_file_hover']['tmp_name'], $overwrite, $homeimage_id);
             if ($file === false) {
                 Flash::set('error', __('Home Main Image has not been uploaded!'));
             }
             if ($file_hover === false) {
                 Flash::set('error', __('Home Hover Image has not been uploaded!'));
             }
             //Add Image to database
             $data = $_POST['homeimage'];
             Flash::set('post_data', (object) $data);
             $homeimage = Record::findByIdFrom('HomeImage', $homeimage_id);
             if (!$homeimage->update('HomeImage', array('filename' => $file), 'id=' . $homeimage_id)) {
                 Flash::set('error', __('Image has not been updated.'));
             } else {
                 if (!$homeimage->update('HomeImage', array('filename_hover' => $file_hover), 'id=' . $homeimage_id)) {
                     Flash::set('error', __('Image has not been updated.'));
                 } else {
                     Flash::set('success', __('Home Image has been updated!'));
                     if (isset($_POST['commit'])) {
                         redirect(get_url('homeimage'));
                     } else {
                         redirect(get_url('homeimage/view/' . $homeimage->id));
                     }
                 }
             }
         }
         Flash::set('success', __('Home Image has been added!'));
     }
     redirect(get_url('homeimage'));
 }
Ejemplo n.º 2
0
    $rank = trim($_POST["rank"]);
    if (empty($rank)) {
        $rank = 1;
    }
    $old_name = $_FILES["file"]["name"];
    $extension = explode(".", $old_name)[1];
    $imageName = uniqid() . "." . $extension;
    $url = $root . "img/" . $imageName;
    $final_path = dirname(dirname(__FILE__)) . "/web/img/" . $imageName;
    move_uploaded_file($_FILES["file"]["tmp_name"], $final_path);
    $hi = new HomeImage();
    $hi->setIname($iname);
    $hi->setUrl($url);
    $hi->setHref($href);
    $hi->setRank($rank);
    $hi->save();
    header("location:homeImagesController.php");
    exit;
}
if ($action === "edit") {
    $id = $_GET["id"];
    $hi_update = new HomeImage();
    $hi_update->setId($id);
    $hi_update->loadById();
    $isEdit = true;
}
if ($action == "modify") {
    // 提交更改
    $hi_modify = new HomeImage();
    $id = $_POST["id"];
    $iname = $_POST["iname"];