News Post/Blog - flat pack system.
Posted: Sat Oct 13, 2012 8:04 am
I was looking for a simple news post/blog type system for the front page of my website.
The website was for image sharing and the posting thing I wanted was just for members to post updates that they have made to image galleries on the website.
All I wanted was a simple form where it stores posts/comments in a file rather than a database.
I ended up writing up my own script.
Its not very fancy or advanced but it did the job for me.
And yes I don't have and file upload security, I couldn't be bothered to be honest, but that would be simple.
You can see an example of this blog thingy at: http://newspost.net63.net/
Anyway here's the code.
As you can see along with the post it displays the date and time posted and also the author, or member...
What I did was incorporate this into my front page in an iframe like so:
The website was for image sharing and the posting thing I wanted was just for members to post updates that they have made to image galleries on the website.
All I wanted was a simple form where it stores posts/comments in a file rather than a database.
I ended up writing up my own script.
Its not very fancy or advanced but it did the job for me.
And yes I don't have and file upload security, I couldn't be bothered to be honest, but that would be simple.
You can see an example of this blog thingy at: http://newspost.net63.net/
Anyway here's the code.
<?php session_start(); $author = $_SESSION['username']; date_default_timezone_set ("/*Your region*/"); $time = date("F j Y g:i a"); //create images folder. if (is_dir('./images/') === false){ mkdir('./images/', 0744); } //if form submitted if (isset($_POST['Submit'])){ $target = './images/'; $target .= rand(0000,9999); $target .= basename($_FILES['file']['name']); $ok=1; //if file uploaded and moved to images folder, write into test.php if (move_uploaded_file($_FILES['file']['tmp_name'], $target)){ //if comment isset then add a <br/> tag to format correctly. if (empty($_POST['comment']) === false ){ $add = "<br/><br/>"; }else{ $add = ""; } $post_pic = '<div class="box"><a target="_blank" href="' . $target . '"><img style="margin-top:-20px;" height="250px" src="' . $target . '" /></a></div>' . $add; $file_pic = "blog.php"; $handle_pic = fopen($file_pic, "a"); fwrite($handle_pic, $post_pic); //if file uploaded and comment is empty, write margin adjustment to test.php if (empty($_POST['comment']) === true ){ $blk = "<h3 style='margin-bottom:50px;' class='font3'>" . $time . " by " . $author . "</h3><br/>\n"; $file = "blog.php"; $handle = fopen($file, "a"); fwrite($handle, $blk); } } //if comment is not empty (posted) then write to test.php if (empty($_POST['comment']) === false ){ $com = stripslashes(ucfirst($_POST['comment'])); $post = '<div style="font-size:15px;color:#fff;margin-top:-20px;margin-bottom:56px;" class="box">' . $com . "<br/><h3 class='font3'>" . $time . " by " . $author . "</h3></div><br/>\n"; $file = "blog.php"; $handle = fopen($file, "a"); fwrite($handle, $post); } header("Location: blog.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Language" content="en-nz" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="http://ajax.googleapis.com/ajax/libs/jq ... "></script> <script> function Scrollit(){ window.scrollBy(0,9999999); } setTimeout('moveWin();',1); </script> <style> body { background-color:#000; color:#fff; } .comment { position: fixed; bottom:0px; left:40px; padding:5px 0 5px 0; z-index:999; } .font1 { font-size:18px; font-weight:100; font-family:arial; float:right; margin: 0 10px 0 10px; } .font2 { font-size:12px; font-weight:100; font-family:arial; margin:5px 0 0 0; } .font3 { font-size:10px; font-weight:100; font-family:arial; color:#555; margin:5px 0 0 0; } </style> </head> <body onLoad="Scrollit();"> <div class="comment"> <h3 class="font1">Comment</h3> <form style="color:white;" name="form" enctype="multipart/form-data" action="blog.php" method="post" > <textarea wrap="hard" name="comment" style="width:558px;height:20px;"></textarea> <br/> <h3 class="font2">Upload Photo <input type="file" name="file"> <input style="float:right;margin:0px 0 0 0" style="float:right;margin-top:5px;" type="submit" name="Submit" value="Post Comment"></h3> </form> </div> <br/><br/>It simply allows the user to type a comment in the textarea and/or upload a image, it is then just written into the same file at the end. So all that is needed is one file for this to work.
As you can see along with the post it displays the date and time posted and also the author, or member...
What I did was incorporate this into my front page in an iframe like so:
<iframe id="frame" frameborder="0" style="z-index:100;margin-top:18px;" width="650px" height="420px" src="blog.php"></iframe>And thats just one line.