Write to .txt

Discussion in 'Website Creation' started by peter_sanders|2, Mar 31, 2011.

  1. I have gotten a web hosting account to get around the problem of PHP and ASP compilation and localization of site. It now works. It is password protected and I have a "journal" of sorts with a PHP script to write to Journal.txt. The problem is that
    every journal entry overwrites the previous.
    I want to keep every entry by writing the next entry to the next available space. This is the current script.

    Sending...

    $d = date("Y/m/d") ;
    $je = $_GET["je"] ;


    $myFile = "Journal.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    $stringData = "$d \n" ;
    fwrite($fh, $stringData);
    $stringData = $je ;
    fwrite($fh, $stringData);
    fclose($fh);

    header( 'Location: http://fgf80homepage.hostoi.com/[insert undisclosed user page here]' ) ;
    ?>

    I have it in the section so that if there is a PHP compilation failure, I will know the next time I go to my website.
     
  2. Also, how does one go about setting up a "favicon," or what ever it is called?
    And, for that matter, how would I write (and process) a form similar to the form on this page for posting a reply? Could I (legally and practically) tweak the source code so that it would write to the journal.txt file? I would prefer this, using the code starting:
    "<p>
    <textarea id="message wrap="physical" cols=" et cetera
     
  3. The capability of having a subject line would also be greatly appreciated.
    in the PHP script, "$je" represents the input variable je from the HTML form on the previous page.
     
  4. So you want to APPEND the new journal entry to the end of the existing file content, and not OVERWRITE the existing data. Thats it in a nutshell.
    I would start by checking the manual page that explains the syntax of the fopen call. This is where you are doing the file open step, opening up that journal file for a write. It may be that you need to use a different code letter instead of the 'w', perhaps a different letter that will open the file for 'appending'. Similarly, I would check the manual page for complete explanation of the fwrite function, check to see if it mentions any special opcode that will do a append type save instead of comple over-writing.
    This script code looks similar to Perl........
     
  5. 7:18 pm response:
    If I can legally use that code, where can I find it?
    It cannot be found completely on this page, and I cannot find the HTML sub-script. If I can legally use it or a variation, pleas help.
    Thank you, and sorry for all the after-thoughts.
     
  6. Probably fopen($myFile, 'a') for append instead of 'w' for write. Looks like PHP language, not Perl.

    If you put 16x16 favicon.ico in your home directory, most browsers treat it as your website icon.

    Not sure I understand your 3rd and 4th questions.
     
  7. @B. Tuthill
    3rd and 4th questions
    I am referring to the box located at the bottom of this page that is used to input comments and responses to a php or asp based information processing pages. I want to know the script for it. I looked in firebug, from which you cannot copy and the process would take weeks by hand, it does not appear in whole (i.e., the html sub-file that makes up the text area) when you right click and hit "view page source," and I would far prefer this box to the box that results form the html tags <input type="text" name="resulting-variable-name">.
    Thank you.
     
  8. Thanks. I am now, for all intents and purposes, done with the journal.
    Now I want to make it so that I click a link at the bottom of the page that will take me to a php page that will download the journal, wipe the online file clean, and redirect me back to my user page. I can do the last two, but how do you initiate an external (relative to individual page) download with the onload event?
    Thank you in advance
     

Share This Page