<?php
function getExtn($filename){
$ext = explode(".",$filename);
return $ext[1];
}
$imgfile="";
include '../connection.php';
$slno = $_POST["slno"];
$descr = $_POST["descr"];
$type = $_POST["type"];
$url = $_POST["url"];
$descr = str_replace("'"," ",$_POST["descr"]);
$title = $_POST["title"];
if($title==""){
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 ="Blog".time().rand(10,100).".".$fileext;
if(move_uploaded_file($sourcePath,"../img/".$imgfile)){
@unlink("../img/".$img);
?>
<?php
}
}
}
if(empty($slno)){
$insert = "insert into blog(title,img,descr,type,url)values('$title','$imgfile','$descr','$type','$url')";
$exc = $mysqli->query($insert);
echo "Blog Add Succesfully";
file_put_contents("blogsss.txt", $insert);
}else{
if(empty($imgfile)){
$update = "update blog set title='$title',descr='$descr',type='$type',url='$url' where id='$slno'";
$exc = $mysqli->query($update);
echo "Blog Update Succesfully";
}else{
$update = "update blog set title='$title',descr='$descr',img='$imgfile' where id='$slno'";
$exc = $mysqli->query($update);
echo "Blog Update Succesfully";
}
}
?> |