Auto Save with PHP

28 May 15 - 11:30

I’m a huge fan of making my life as simple as possible.

So in light of that, I’ve written a markdown based blogging engine for this website which basically consists of a dynamically resizing textarea. I write and submit my blog posts in markdown, these then get converted into HTML and both get stored in the database.


As you can see, I take a minimalistic approach because I like to keep it clean and simple. This works well. I have drop down lists (home) which determine whether it gets posted on the front page, under experiences or if it is just a positive experience. And (draft) determines whether I am done with the post or not. If I am not and I click on “Publish” it simply saves it to my drafts page. From there I can re-visit, edit and delete posts without them seeing a glimpse of daylight.

I also have an image uploader (not developed by myself) which allows me to drag and drop images into it. This uploads them automatically and I am then able to use them in my blog posts.

###So why haven’t I been using it? The biggest problem I’ve had with it, is that if anything went wrong (browser crash, didn’t hit save, closed the tab by accident), my entire post would be lost. This has happened quite a few times already on some rather long posts.

###What to do? Well, the most logical thing to do, was to create an auto save function. Something which would save the state of my post every couple of seconds to the database, as a draft by default. Using this method, I could just pick up where I left off even after I wasn’t paying attention and closed my browser. It also has the advantage of allowing me to start a blog post on my laptop, flesh it out on my tablet and then post it from my mobile while on the go.

I will be sharing how I have done this in a separate post