Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts

    edit flat file blog records

    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?
    Last edited by danielandlisa; 03-19-2010 at 12:44 PM. Reason: type wrong

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    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?

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?
    Last edited by danielandlisa; 03-19-2010 at 12:50 PM.

  • #4
    New Coder
    Join Date
    Dec 2009
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?

    <?php
    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
    exit;
    } 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
    }
    ?>

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    Give a sample of your flat file database ...
    What does one of the lines look like?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •