<?php
function getExtn($filename){
$ext = explode(".",$filename);
return $ext[1];
}
$imgfile="";
include '../connection.php';
$slno = $_POST["slno"];
$category = $_POST["category"];
$title = $_POST["title"];
$statu = $_POST["statu"];
$descr = $_POST["descr"];
$descr = str_replace("'"," ",$_POST["descr"]);
if($category=="Select Category"){
echo "Fill All Details";
exit();
}
if(is_array($_FILES)){
if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
$sourcePath = $_FILES['userImage']['tmp_name'];
$fileext = getExtn($_FILES['userImage']['name']);
$imgfile ="gallery".time().rand(10,100).".".$fileext;
if(move_uploaded_file($sourcePath,"../img/".$imgfile)){
@unlink("../img/".$img);
?>
<?php
}
}
}
if(empty($slno)){
$insert = "insert into gallery(category,title,img,status,descr)values('$category','$title','$imgfile','$statu','$descr')";
$exc = $mysqli->query($insert);
echo "Gallery Add Succesfully";
}else{
if(empty($imgfile)){
$update = "update gallery set category='$category',title='$title',status='$statu',descr='$descr' where id='$slno'";
$exc = $mysqli->query($update);
echo "Gallery Update Succesfully";
}else{
$update = "update gallery set category='$category',title='$title',status='$statu',img='$imgfile',descr='$descr' where id='$slno'";
$exc = $mysqli->query($update);
echo "Gallery Update Succesfully";
}
}
?> |