Flat File Blogging with FlatPress

If you’re into blogging and host your own blog, you are aware of the need for MySQL databases when you install most blogging platforms, and this is because most blogging programs, and indeed most content management systems store their data in a database. This is generally not a problem because most web hosts offer MySQL databases. But there are situations where you may not have or want to use a database.

Flatpress is a standard-compliant multi-lingual extensible blogging engine which does not require a database to work. Better yet, it’s open source. FlatPress stores all of its content on text files and therefore you don’t need a MySQL database. Installing it is a breeze, and you can get several themes to work with. Theming is done with Smarty and PHP, and the Wiki on the official Flatpress site has some useful information on this and other topics. There are a good number of plugins available, including Akismet, Categories, Calender, etc. Flatpress also has the ability to use widgets using the blockparser plugin.

All in all, FlatPress looks like it’s worth exploring, and is something I will be looking at and playing with more.

Have you used or do you use FlatPress? Please share your thoughts and experiences with us.

How to bulk transfer many files over FTP using PHP

Have you ever wanted to transfer/upload many files using FTP, and sat there for hours watching the process and hoping that your FTP connection doesn’t time out?? Well, I have. This especially happens when I am uploading images, or a CMS. Well, I learned a little trick from Bo on how to use zipped files and PHP to make the file transfer process less painful.

This is how you do it:

Step 1: Zip everything you want copied.
Step 2: Upload the Zip file.
Step 3: Create a PHP file in the same directory called unzip.php and put this code in it:

  <?php<br />
echo '</p>
<pre>';<br />
system('unzip your_file.zip');<br />

Step 4: Run the PHP file in a browser (you should see the unzip output).
Step 5: Remove the zip file and the unzip.php file from your server.
Step 6: Rejoice that you just saved yourself a hour of waiting!

Isn’t that nice?

PHP and MySQL for Dynamic Websites

The other day I was browsing Amazon.com trying to find a good PHP/MySQL book for my easily distracted mind to focus on. I have been making starts and stops in my PHP journey for some time now mostly because I was busy with school, but also because I couldn’t seem to find a good resource to help me get started and moving fast. The book that I had contemplated using before when I started working on improving my PHP skills fell short because it covered outdated versions of PHP and MySQL so I was constantly running into all kinds of errors.

Well, I think I finally solved my problem! I think I finally found the book that I’ve been looking for:

This book is great for several reasons. One, it’s laid out in a very easy to follow manner. It starts you off with just PHP, and has you building a nice dynamic website just with HTML/CSS and PHP by the second chapter. You get all the code so you can type it all out, but you can also download it from the accompanying website. I prefer to type it out because then I learn better. After you’ve got the basics of PHP under your belt, Larry moves you into MySQL and databases, and while I haven’t got there yet, I can tell by browsing through that he has done a thorough job covering as many details as he can in a book of that size. At the end, everything comes together, and you build several applications to test your knowledge and to whet your appetite for more.

Being the geek I am, I never buy a book or a gadget without reading as many reviews as I can find, and PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition) (Visual QuickPro Guide) has excellent reviews at Amazon.com, and I definitely highly recommend it.

By the way, the second edition covers PHP 5 and MySQL 4.1, so you’re pretty up to date, and Appendix A guides you through the installation process. I’m excited to start working through this book!!

Venturing into flat-file Content Management Systems

Life has been busy with school and all taking up an inordinate amount of my time. However, I have also been playing around with some small coding projects. I have some big ideas but they’re going to need a lot of time to build. I realized that to get these projects off the ground I’ll need to really buckle down and work on my PHP coding skills, so these projects will have to wait till next year.

Apart from that, I’ve been working on some small website projects using PHP, and one thing I’ve been playing with is the concept of flat-file content management systems. These are content management systems that don’t use a database to store information, but instead, the information is stored in text files. If you have worked with any of the database-based content management systems before, such as Joomla, Mambo, or MODX, you know that they are pretty heavy duty, and sometimes resource hungry because of all the utility and functionality that the try to provide.
Flat file CMS’s are ideal for smaller websites that don’t require loads of information to be pulled from many different places at the same time. Since I am just starting to explore these kinds of systems, all I want to do in this post is introduce the concept to you and explain why I think it’s such an attractive option. Here are advantages, I am finding, of using a flat-file CMS:

  1. I don’t need a database – This is useful because one of the hosting accounts I use offers only a limited number of mySQL databases, but unlimited add-on domains. So I can reserve the mySQL databases for my bigger websites and use flat-file CMSs for my smaller websites. With today’s ever-expanding hosting solutions, this might not be an issue for most people, but it’s definitely an advantage to keep in mind.
  2. Installation is easy – Flat-file CMSs are a breeze to install and setup, since all the configuration information is in easily accessible files.
  3. Updates are easy -Unlike most major CMSs where updates involve going back and figuring out what to do with all your plugins, and what files had you edited where, updating flat-file CMSs is a breeze since changes are usually to specific files and are easy to implement. And because you’re not working with databases, updates are an easy DIY task.
  4. Editing and tweaking is easy – Most of the flat-file CMSs that I have had a chance to glance at are written in PHP, so they are easy to figure out and tweak. As I mentioned in a previous post, playing with CMSs is a great way to master PHP.

There are a number of flat-file CMSs out there and I will be talking about them in future posts. The one that I am currently dabbling with is NanoCMS, a nice little flat-file CMS that is proving to be quite useful and easy to play with, so you may want to check it out if you need to whip up a quick website without much ado.

Converting csv to sql using php

In previous posts we’ve discussed getting your csv files into sql format using different methods. I walked you through the process from csv to sql using HeidiSQL and PHPMyAdmin. I then did a follow up on how to import a large csv file into a MySQL database using the MySQL command prompt. In all these instances, what we were essentially doing was creating queries, just in different ways.

Well, today I want to present you with another method of getting your csv file into sql, using PHP code. For this piece of code, the full credit goes to legend. You need to make sure the database is already created before you dump the date.

/* Code at http://legend.ws/blog/tips-tricks/csv-php-mysql-import/
/* Edit the entries below to reflect the appropriate values
$databasehost = “localhost”;
$databasename = “test”;
$databasetable = “sample”;
$databaseusername =”test”;
$databasepassword = “”;
$fieldseparator = “,”;
$lineseparator = “\n”;
$csvfile = “bbqrest.csv”;
/* Would you like to add an ampty field at the beginning of these records?
/* This is useful if you have a table with the first field being an auto_increment integer
/* and the csv file does not have such as empty field before the records.
/* Set 1 for yes and 0 for no. ATTENTION: don’t set to 1 if you are not sure.
/* This can dump data in the wrong fields if this extra field does not exist in the table
$addauto = 0;
/* Would you like to save the mysql queries in a file? If yes set $save to 1.
/* Permission on the file should be set to 777. Either upload a sample file through ftp and
/* change the permissions, or execute at the prompt: touch output.sql && chmod 777 output.sql
$save = 1;
$outputfile = “output.sql”;

if(!file_exists($csvfile)) {
echo “File not found. Make sure you specified the correct path.\n”;

$file = fopen($csvfile,”r”);

if(!$file) {
echo “Error opening data file.\n”;

$size = filesize($csvfile);

if(!$size) {
echo “File is empty.\n”;

$csvcontent = fread($file,$size);


$con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
@mysql_select_db($databasename) or die(mysql_error());

$lines = 0;
$queries = “”;
$linearray = array();

foreach(split($lineseparator,$csvcontent) as $line) {


$line = trim($line,” \t”);

$line = str_replace(“\r”,””,$line);

This line escapes the special character. remove it if entries are already escaped in the csv file
$line = str_replace(“‘”,”\'”,$line);

$linearray = explode($fieldseparator,$line);

$linemysql = implode(“‘,'”,$linearray);

$query = “insert into $databasetable values(”,’$linemysql’);”;
$query = “insert into $databasetable values(‘$linemysql’);”;

$queries .= $query . “\n”;



if($save) {

if(!is_writable($outputfile)) {
echo “File is not writable, check permissions.\n”;

else {
$file2 = fopen($outputfile,”w”);

if(!$file2) {
echo “Error writing to the output file.\n”;
else {


echo “Found a total of $lines records in this csv file.\n”;


So that is one nice easy way to do it, and the code is easy to follow and understand, so that you can mod and adapt it to your needs. Many thanks to legend for this code.