';
include "footer.php";
exit;
}
if (isset($_POST['filename']) && $_POST['filename'] != '') {
include "../config.php";
//canging space to -
$filename = preg_replace('/[^a-zA-Z0-9\']/', '-', $_POST['filename']);
$filename = strtolower(str_replace("'", '', $filename));
$filename .= ".php";
//makeing blog page
$myfile = fopen($filename, "w") or die("Unable to open file!");
$txt_contant = '
'.$_POST['title'].'
';
fwrite($myfile, $txt_contant);
fclose($myfile);
//upload image
$target_dir = "images/";
$target_file = $target_dir . basename($_FILES["img"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
$check = getimagesize($_FILES["img"]["tmp_name"]);
if ($check !== false) {
$uploadOk = 1;
} else {
$uploadOk = 0;
}
if (file_exists($target_file)) {
$uploadOk = 0;
}
if ($_FILES["img"]["size"] > 5*1048576) {
$uploadOk = 0;
}
if ($imageFileType != "webp" && $imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif") {
$uploadOk = 0;
}
if ($uploadOk == 1) {
if (!move_uploaded_file($_FILES["img"]["tmp_name"], $target_file)) {
die('Sorry, there was an error uploading your file.
');
}
}
$sql = "INSERT INTO `blog_post`( `title`, `short_description`, `image_url`, `page_url`) VALUES ('".mysqli_real_escape_string($conn, $_POST['title'])."','".mysqli_real_escape_string($conn, $_POST['short_description'])."','/blog/".mysqli_real_escape_string($conn, $target_file)."','/blog/".mysqli_real_escape_string($conn, $filename)."');";
if ((mysqli_query($conn, $sql))) {
echo '
Blog created successfully
';
} else {
echo '
' . $sql . '
' . mysqli_error($conn).'
';
}
}
?>