View Full Version : edit flat file blog records

03-19-2010, 01:25 PM
Hi, i gotta flat file blog that i made myself and it works good but i want to add some functions to edit and delete posts im not sure how to do this would it be possible?
i was thinking something like opening the text files and being able to edit them
in a form field.
i also want to add suport for image uploads along with the posts, is that possible?

03-19-2010, 01:29 PM
With a flat-file database, it can be done, but it's a lot of work to add those functions,
especially images ... as they need to be not only uploaded, but added to the text of
the posts. That will require some sort of text editor.

Is there a reason you are not using WordPress for your blog?

03-19-2010, 01:46 PM
i know mysql and wordpress would be better but it have to be done this way.

the image uploads isnt necessary but i would like to add the edit and delete posts option.
is it really that hard to open up the file and overwrite it?

03-19-2010, 03:04 PM
i did this and it works to delete records by entering the line to delete

wouldnt it be able to get the records from the flatfile shown on the page so you could choose what line to edit or delete?

if (isset($_POST['rad'])) {
$fil = "blog.txt"; // File to delte or change
$input = "<---"; // what will be written on the line instead
$nasta = "next_page.php"; // page to be shown after submit

$rad = $_POST['rad'];
$cont = file($fil); // reads file into a array
$fh = fopen($fil, "w+"); // opens the file
for($i=0; ; $i++) {
if($cont[$i] == '') {break;} else {
if($i == $rad) {
fwrite($fh, "$input\r\n"); } else {
fwrite($fh, $cont[$i]); }
fclose($fh); // closes the file
header("location: $nasta"); // sends user to next page
} else {
echo"<form method=\"post\">
Rad som ska tas bort: <input type=\"text\" name=\"rad\"> <input type=\"submit\" value=\"Ta Bort!\">
</form>"; // Echo out the form

03-19-2010, 05:20 PM
Give a sample of your flat file database ...
What does one of the lines look like?