<?php
include('../helpers/init.php');
if(isset($_POST['addGalleryImage'])){
    
	$client = $_POST['clid'];
    $error = "";    
	$image="iip_".rand(111,999)."_".basename($_FILES['file']['name']);
    $fileinfo = @getimagesize($_FILES["file"]["tmp_name"]);
        $width = $fileinfo[0];
        $height = $fileinfo[1];
    
	if($_FILES['file']['size']>250000){
			header('Location:../pages/add-gallery.php?&result=picfailer');
	}
    
    if($width > "850" || $height > "550"){
			header('Location:../pages/add-gallery.php?&result=picfaild');
	}
    else{
		if (do_upload($image,"project-gallery")){
		$sql = "insert into pgallery(picture) values('$image')";
		if(query($sql)){
			header('Location:../pages/add-gallery.php?&result=success');
		}else{
			$error = error();
			header('Location:../pages/add-gallery.php?&result=failer');
		}
		}
	}/*end else for size validation*/
	
	
}

//-----------------------Add Image Edns Here ---------------


if(isset($_GET['action']) && $_GET['action']=="deleteGalleryImage"){
	$id=$_GET['id'];
	$data = getWhere("pgallery","id",$id);
    foreach($data as $row){
		$image= $row['picture'];
        $banner = "../uploads/project-gallery/".$image;
        
		$sql = "delete from pgallery where id=$id";
        
		if(query($sql)){  
            unlink($banner);
			header('Location:../pages/add-gallery.php?&result=vsuccess');
		}else{
			header('Location:../pages/add-gallery?&result=failer');
		}
	}
}

?>