<?php
$pageName = "New Post";
include($_SERVER['DOCUMENT_ROOT']."/admin/layout/header.php");
if(isset($_POST['newblog_post'])) {
$title = $_POST['title'];
$tagline = $_POST['tagline'];
$content = $_POST['content'];
if (empty($title) || empty($tagline) || empty($content)) {
toast_alert('error', 'Fill Required Form');
} else if(empty($_FILES['image'])){
toast_alert('error', 'Upload Blog Image');
}else{
if (isset($_FILES['image'])) {
$file = $_FILES['image'];
$name = $file['name'];
$path = pathinfo($name, PATHINFO_EXTENSION);
$allowed = array('jpg', 'png', 'jpeg');
$folder = "../assets/front/img/blog/";
$n = time() . $name;
$destination = $folder . $n;
}
if (move_uploaded_file($file['tmp_name'], $destination)) {
$category = "Press Release";
$uploadnft = "INSERT INTO blog (title,tagline,content,category,image)
VALUES(:title,:tagline,:content,:category,:image)";
$stmt = $conn->prepare($uploadnft);
$stmt->execute([
'title' => $title,
'tagline' => $tagline,
'content' => $content,
'category' => $category,
'image' => $n
]);
if (true) {
toast_alert("success", "Blog Posted", "Success!");
} else {
toast_alert("error", "Sorry Something Went Wrong !");
}
}
}
}
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Create New Post
</h1>
<ol class="breadcrumb">
<li><a href="./dashboard"><i class="fa fa-dashboard"></i> Dashboard</a></li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<form method="POST" enctype=multipart/form-data>
<!-- SELECT2 EXAMPLE -->
<div class="box box-default">
<div class="box-header with-border">
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i
class="fa fa-minus"></i></button>
</div>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="row">
<div class="col-md-6">
<!-- /.form-group -->
<div class="form-group">
<label for="exampleInputEmail1">Post Title</label>
<input type="text" maxlength="40" minlength="10" class="form-control" placeholder="Blog Title"
name="title">
</div>
<!-- /.form-group -->
</div>
<!-- /.col -->
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputEmail1">Post image (JPG, PNG, GIF. Max size: 100)
MB</label>
<input type="file"
class="form-control"
placeholder=" JPG, PNG, GIF, SVG, MP4, WEBM. Max size: 100 MB" name="image" required />
<input type="hidden" name="MAX_FILE_SIZE" value="10485760" />
</div>
</div>
<!-- /.col -->
</div>
<div class="row">
<div class="col-md-12 offset-md-2">
<div class="row">
<div class="col-md-12">
<label for="" class="text-center text-info">Post Tagline</label>
<input type="text" maxlength="150" minlength="30" class="form-control" placeholder="Blog Tagline"
name="tagline">
</div>
<div class="col-md-12">
<div class="box-body pad">
<textarea class="textarea" placeholder="Post Content"
name="content" maxlength="1500" minlength="100"
style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"
required></textarea>
</div>
</div>
</div>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" name="newblog_post" class="btn btn-primary">Create New blog post</button>
</div>
</div>
</form>
<!-- /.box -->
<!-- /.row -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php
include($_SERVER['DOCUMENT_ROOT']."/admin/layout/footer.php");
?>
Back to Directory