PHP Classes

PHP Article System for Posts: Create and manage posts stored in a database

Recommend this page to a friend!
  Info   View files Example   View files View files (14)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 67 All time: 10,227 This week: 189Up
Version License PHP version Categories
postclass 1.0The PHP License5PHP 5, Databases, Content management
Description 

Author

This package can create and manage posts stored in a database.

It provides a class that can perform the basic operations to store and retrieve posts stored in a database table.

Currently, it implements the article post operations:

- Create a new post

- List created posts

- Retrieve a single post

- Update an existing post

- Delete a post

The class stores an article post in a database table record. That record stores a title, HTML content, image, and the last update date.

A separate class establishes MySQL database connections using the MySQLi extension.

A different configuration script contains the database access parameters.

Picture of Ahmed Khan
Name: Ahmed Khan <contact>
Classes: 9 packages by
Country: Pakistan Pakistan
Age: ???
All time rank: 245134 in Pakistan Pakistan
Week rank: 568 Up9 in Pakistan Pakistan Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php

include 'header.php';
include
'postclass.php';
       
$crud = new Post();
$errors = [
   
'article_name' => null,
   
'article_category' => null,
   
'article_content' => null,
   
'article_img' => null,
   
'form' => null,
];

$conne = '';
$form = true;
$target_dir = "postimages/";
$target_file = null;
$imageFileType = null;
if (!empty(
$_POST)) {

   
$target_file = $target_dir . basename($_FILES["article_img"]["name"]);
   
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
   
$check = getimagesize($_FILES["article_img"]["tmp_name"]);
    if (empty(
$_POST['a_name'])) {
       
$errors['article_name'] = "Please Enter Your Title";
       
$form = false;
    }
    if (
$check === false) {
       
$errors['article_img'] = 'Image is required';
       
$form = false;
    } elseif (
$imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
       
$errors['article_img'] = 'Sorry, only JPG, JPEG, PNG & GIF files are allowed.';
       
$form = false;
    }

    if (empty(
$_POST['article_content'])) {
       
$errors['article_content'] = "Please Fill Your Content";
       
$form = false;
    }

    if (
$form) {

       
$articlename = $_POST['a_name'];
       
$articlecont = $_POST['article_content'];
       
       
$image = rand(1, 100);
       
$imgname = $image . "." . $imageFileType;
       
$result = $crud->insertpost($articlename, $articlecont, $imgname);

        if (
$result == 'true') {
           
move_uploaded_file($_FILES["article_img"]["tmp_name"], $target_dir . $imgname);
           
header('Location: index.php');
            return;
        } else {
           
$errors['form'] = $result;
        }

    }

} else {
   
$errors['form'] = "Kindly Fill All the Fields";
}

?>
<!--<script type="text/javascript" src="tinymce/tinymce.min.js"></script>-->
<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
    <script type="text/javascript">
        // tinymce.init({
        // selector: "#article_content"
        // });

bkLib.onDomLoaded(function() {
  new nicEditor().panelInstance('article_content');

});
    </script>

<form class="form-horizontal" method="post" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<fieldset>

<!-- Form Name -->
<legend>Create Post</legend>

<!-- Text input-->
<div class="form-group col-md-10">
  <label class="control-label" for="a_name">Create Post</label>

  <input id="a_name" name="a_name" type="text" placeholder="Enter Title For Your Article" class="form-control input-md" value="<?php if (isset($_POST['a_name'])) {echo $_POST['a_name'];}
?>" required>
    <p class="text-danger"><?php echo $errors['article_name'] ?></p>

</div>

<!-- File Button -->
<div class="form-group col-md-10">
  <label class="control-label" for="article_img">Upload Image</label>

    <input id="article_img" name="article_img" class="input-file" type="file" required>

     <p class="text-danger"><?php echo $errors['article_img'] ?></p>

</div>

<!-- Textarea -->
<div class="form-group col-md-10" >
  <label class="control-label" for="article_content">Content</label>

    <textarea class="form-control" id="article_content" name="article_content" rows="13"><?php if (isset($_POST['article_content'])) {echo $_POST['article_content'];}
?></textarea>
    <p class="text-danger"><?php echo $errors['article_content'] ?></p>

</div>

<!-- Button -->
<div class="form-group col-md-10">
  <label class="control-label" for="submit"></label>

    <button id="submit" name="submit" type="submit" class="btn btn-success">Publish</button>
    <p class="text-danger"><?php echo $errors['form'] ?></p>

</div>

</fieldset>
</form>


<?php include 'footer.php';?>


  Files folder image Files  
File Role Description
Files folder imagepostimages (1 file)
Accessible without login Plain text file createpost.php Example Example script
Accessible without login Plain text file dbconfig.php Conf. Configuration script
Plain text file DbConnection.php Class Class source
Accessible without login Plain text file deletepost.php Example Example script
Accessible without login Plain text file footer.php Aux. Auxiliary script
Accessible without login Plain text file header.php Aux. Auxiliary script
Accessible without login Plain text file index.php Aux. Auxiliary script
Accessible without login Plain text file LICENSE Lic. License text
Plain text file postclass.php Class Class source
Accessible without login Plain text file posts.sql Data Auxiliary data
Accessible without login Plain text file postview.php Example Example script
Accessible without login Plain text file README.md Data Read me
Accessible without login Plain text file updatepost.php Example Example script

  Files folder image Files  /  postimages  
File Role Description
  Accessible without login Image file 88.png Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:67
This week:0
All time:10,227
This week:189Up