//insert object $text_image in $_SESSION['change_image'] array $_SESSION['change_image'] = $text_image; //var_dump($_SESSION); } /*****************************************************************************************************/ // if click on button Save on this page if (isset($_POST['save'])) { $text_image = new ImageSlider(); if (!empty($_FILES['fup_image'])) { move_uploaded_file($_FILES['fup_image']['tmp_name'], "./../img/" . $_FILES['fup_image']['name']); $text_image->image_slider_id = $_POST['image_slider_id']; $text_image->image_slider_url = $_FILES['fup_image']['name']; //when data sent from the form we must update data in $_SESSION['change_image'] $_SESSION['change_image'] = $text_image; //insert updated object $text_image in $_SESSION['change_image'] again $text_image->save(); echo "<div class='alert alert-success'> \n <i><strong>Image successfully updated. :)</strong></i>\n </div>"; } //var_dump($_SESSION); } /*****************************************************************************************************/ ?> <br> <h3>Change image</h3> <strong style="color: red;">Caution: picture size must be 1920x1280px.</strong> <br> <br> <img class="img-responsive" style="width: 500px; border-radius: 3px;" src="./../img/<?php echo $_SESSION['change_image']->image_slider_url; ?>
if (isset($_FILES['file'])) { //The error validation could be done on the javascript client side. $errors = array(); $file_name = $_FILES['file']['name']; //echo 'the file name is : '.$file_name; $file_size = $_FILES['file']['size']; $file_tmp = $_FILES['file']['tmp_name']; $file_type = $_FILES['file']['type']; $file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); $extensions = array("jpeg", "jpg", "png", "gif"); if (in_array($file_ext, $extensions) === false) { $errors[] = "image extension not allowed, please choose a JPEG or PNG file."; } if ($file_size > 2097152) { $errors[] = 'File size cannot exceed 2 MB'; } if (empty($errors) == true) { //now before uploading the picture...i need to rename it $uniqueFileName = Common::constructUniqueFileName($file_name, $file_ext, 'IPS', 'tbl_home_page_image_slider', 'image_id'); move_uploaded_file($file_tmp, "image_slider/" . $uniqueFileName); $now = date("Y-m-d h:i:sa"); echo $fname . " uploaded file: " . "image_slider/" . $file_name; //after finishing uploading...lets save this info to the database... $imageSlider = new ImageSlider('image_slider', $uniqueFileName, $now, $modifiedBy, $now); $imageSlider->save(); } else { print_r($errors); } } else { echo 'Something went wrong...'; }
if (isset($_POST['edit'])) { $text_image = ImageSlider::get($_POST['edit']); $_SESSION['change_text'] = $text_image; // print_r($_POST); echo '<br>'; //print_r($_SESSION); } if (isset($_POST['save'])) { $edit_text_image = new ImageSlider(); $edit_text_image->image_slider_id = $_POST['image_slider_id']; $edit_text_image->image_slider_subtitle = $_POST['image_slider_subtitle']; $edit_text_image->image_slider_title = $_POST['image_slider_title']; $edit_text_image->image_slider_status = $_POST['cb_visibility']; //var_dump($edit_text_image); //print_r($_POST); $edit_text_image->save(); echo "<div class='alert alert-success'> \n <i><strong>Text successfully updated. :)</strong></i>\n </div>"; $new = ImageSlider::get($_POST['image_slider_id']); //print_r($new); $_SESSION['change_text'] = $new; //print_r($_SESSION); } var_dump($_SESSION); ?> <img style="width: 500px; border-radius: 3px;" src="./../img/<?php echo $_SESSION['change_text']->image_slider_url; ?> "> <br><br><br>