Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: Save form data in a txt file with current date in file name

  1. #21
    Join Date
    Aug 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've cracked the loop by myself here the code
    PHP Code:
    <?php
    $filename
    "filecount.txt" ;
    $fd fopen ($filename "r") or die ("Can't open $filename") ;
    $fstring fread ($fd filesize ($filename)) ;

    for (
    $i $fstring; ; $i--) {
        if (
    $i <= 0) {
            break;
        }
    include(
    'write/'.$i.'.txt');
    }

    fclose($fd) ;

    ?>
    And Link
    http://yabadabadoo.blackapplehost.co..._all_files.php

    Still no space or break between Post's also the loop gets all files and is not limited to 20 files.
    Last edited by trazix; 06-28-2009 at 11:50 AM.

  2. #22
    Join Date
    Aug 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've now managed to seperate the files with a space and border, however there is a strange line at the top and down a few posts.

    [edit] the strange lines are empty divs where a file is missing except the first one dont know what is causing it.

    [Another edit]Ok deleted all files and reposted 30 times, now first file 0.txt is missing and at top of page an empty div is created.

    Link
    http://yabadabadoo.blackapplehost.co...all_files2.php
    PHP Code:
    <?php
    $filename
    "filecount.txt" ;
    $fd fopen ($filename "r") or die ("Can't open $filename") ;
    $fstring fread ($fd filesize ($filename)) ;

    for (
    $i $fstring; ; $i--) {
        if (
    $i <= 0) {
            break;
        }
    echo 
    "<div style='border: 1px #6D7B8D solid;'>";
    include(
    'write/'.$i.'.txt');
    echo 
    "</div><br>";
    }

    fclose($fd) ;

    ?>
    Last edited by trazix; 06-28-2009 at 11:50 AM.

  3. #23
    Join Date
    Aug 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok here is where I am now, I've managed to get it to only display the last 10 post's by counting back 11 (why 11 and not 10 I dont know) probably something to do with that blank div at the top of page which i also managed to get rid of with this line $fstring_two = $fstring-1; . Not bad for an amature.

    Anyway creating a link at bottom of page that will link to another 10 previous posts is proving hard to find a solution to, any ideas would be apreciated.

    Link
    http://yabadabadoo.blackapplehost.co...all_files3.php
    PHP Code:
    <?php

    $filename
    "filecount.txt" 
    // Store file name to $filename

    $fd fopen ($filename "r") or die ("Can't open $filename") ; 
    // Opens file and read's it's contents

    $fstring fread ($fd filesize ($filename)) ; 
    // Stores file contents to $fstring

    $fstring_two $fstring-1;
    //This stops a blank div displaying at top of page

    $loop=$fstring-11;
    //Set's a value of $fstring - 11 to $loop and only display's the last 10 entries


    for ($i $fstring_two; ; --$i) {
        if (
    $i <= $loop) {
            break;
        } elseif (
    $i <= 0){
          break;  
    }

    echo 
    "<div style='border: 1px #6D7B8D solid;'>";
    // Writes Html

    include('write/'.$i.'.txt');
    // Includes txt files from write folder

    echo "</div><br>";
    // Writes Html

    }

    fclose($fd) ;
    // Closes filecount.txt

    ?>
    Last edited by trazix; 06-28-2009 at 11:50 AM.

  4. #24
    Join Date
    Aug 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've integrated some of the older code with the newer code and have come up with this so far.
    [Link]
    http://yabadabadoo.blackapplehost.com/_AAA/TEST.php

    PHP Code:
    <html>
    <head>
    </head>
    <body>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <textarea name="msg"></textarea>
    <input type="submit" value="submit">
    </form>


    <?php
    if (isset($_POST['msg'])){
    //process message if submitted
        
    if (file_exists("filecount.txt")){
        
    //find out if there is a file count file
            
    $filename file_get_contents("filecount.txt");
            
    //if so, use the stored number as the filename
        
    } else {
        
    //if not,
            
    $filename 1;
            
    //set the filename to "1"
            
    $fCount fopen("filecount.txt""w");
            
    //then create the file count file
            
    fwrite($fCount"2");
            
    //set its contents to "2", which will be the next filename
            
    fclose($fCount);
            
    //and close it
        
    }
        
    $input $_POST['msg'];
        if (!
    file_exists("write/$filename.txt")){
        
    //if the filename is not already in use,
            
    $fp fopen("write/$filename.txt""w");
            
    fwrite($fp$input).'&nbsp;'
            
    fclose($fp);
            
    //write the submitted message to a file using the file name
            
    $fInc fopen("filecount.txt""w");
            
    //then, open the file count file
            
    fwrite($fInc, (++$filename));
            
    //add one to the value and rewrite it (now it's ready for the next submission)
            
    fclose($fInc);
            
    //and close it
        
    }
        
    function 
    directory($result) {
    /* This file shows the last 10 files posted to write directory */

    $filename"filecount.txt" 
    // Store file name to $filename

    $fd fopen ($filename "r") or die ("Can't open $filename") ; 
    // Opens file and read's it's contents

    $fstring fread ($fd filesize ($filename)) ; 
    // Stores file contents to $fstring

    $fstring_two $fstring-1;
    //This stops a blank div displaying at top of page

    $loop=$fstring-11;
    //Set's a value of $fstring - 11 to $loop and only display's the last 10 entries


    for ($i $fstring_two; ; --$i) {
        if (
    $i <= $loop) {
            break;
        } elseif (
    $i <= 0){
          break;  
    }

    echo 
    "<div style='border: 1px #6D7B8D solid;'>";
    // Writes Html

    include('write/'.$i.'.txt');
    // Includes txt files from write folder

    echo "</div><br>";
    // Writes Html

    }

    fclose($fd) ;
    // Closes filecount.txt
    }
    echo 
    '<b>Comments submitted so far:</b>';
    echo 
    directory($result);
    }
    ?>
    </body>

    </html>

Bookmarks

Posting Permissions

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