Results 1 to 18 of 18

Thread: question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    question

    do you guys know how i can write stuff to a text file in my php area?

    for e.g. to currently view my php stuff through webpage this is what i do:

    http://localhost/<dir>/filename

    or

    http://<my-ip>/<dir>/filename

    (e.g.: http://localhost/login.html)

    i want to know how i can write to a file called Pyscho.txt, and then view this file on the web by, for.e.g

    http://localhost/Pyscho.txt

    any help would be greatly appreciated

    ps: my pages and files are in the 'www' directory (this is where all php files are kept i think)

  2. #2
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: question

    Hi,
    Look at http://us2.php.net/fopen, also, check out the ' See also' links half way down the page, it will have information on how to write to the file.

    Good luck
    {yak}

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: question

    thanks ill read that but what im trying to do is someting like:

    http://localhost/fwrite.php<something-here> (navigate from the web - not sure aboutt he syntax of the link? can someone give the correct one?)

    and in the file fwrite.php i have to have a function for writing text to test.txt?

  4. #4
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: question

    I'm not sure I understand? Create a page called fwrite.php, and put in your code to write to whatever text file. Then to run the page, you go to: http://localhost/fwrite.php
    Or did you mean like, http://localhost/fwrite.php?file=filenamehere
    Or am I misunderstanding you completley?
    {yak}

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: question

    well a freind of mine had something like:

    www.his-site.org/fwrite.php?entry=blah

    and it used to write the word 'blah' to the text file called 'test.txt'

    which could be viewed by:

    www.his-site.org/test.txt

    i hope you understand me now, thanks for your replies and help.

  6. #6
    Fanatic Member
    Join Date
    Oct 2004
    Posts
    751

    Re: question

    Oh, I think I see what hes doing..
    Did you put a textbox on your page and a submit button and want it to write out to a file?
    My Projects: [ Instant Messagener Client/Server ] [ VBPictochat ]

    My Sites:
    [ Datanethost ]
    [ Helpdesk ]

    Remember if my post was helpful then Rate This Post.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: question

    yes thats bang on!!

    i got a text box there and when i click the button i want it to write the contents of this text box to the file

    (by the way, this textbox and button is on a vb form so im using the webBrowser component to do something like:

    web.Navigate "http://localhost/fwrite.php?..whateverhere )
    but what i need is how to construct the link and the fwrite.php file
    Last edited by Pouncer; Sep 15th, 2005 at 07:53 PM.

  8. #8
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: question

    Ok that helps. You're going to use $_GET['name of parameter'] to retreive the value. and then write that to the file, you can look at the link I gave you to write the file but this is an example, kinda

    PHP Code:
        $value $_GET['txt']);
        
        if(!isset(
    $value))
        {
            
    // theres no value...redirect or something
        
    }
        
    // now do your insert code, of course you validate $value to make sure everything is what you want
        // when you write to your txt file, write $value.
        // your link would look like http://localhost/fwrite.php?txt=and then the value of your vb text box or whatever 
    {yak}

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: question

    thank you, that helps me, ill work on it now and post my results back!!

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: question

    im getting a strange error:

    im using this:

    wb.Navigate "http://localhost/fwrite.php?txt=testline"

    and getting an error:

    Parse error: syntax error, unexpected T_IF in c:\wamp\www\fwrite.php on line 6

    This is the code from the fwrite.php file:

    PHP Code:
    <?php
    $filename 
    'test.txt';
    $somecontent $_GET['txt'

    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {

       
    // In our example we're opening $filename in append mode.
       // The file pointer is at the bottom of the file hence 
       // that's where $somecontent will go when we fwrite() it.
       
    if (!$handle fopen($filename'a')) {
             echo 
    "Cannot open file ($filename)";
             exit;
       }

       
    // Write $somecontent to our opened file.
       
    if (fwrite($handle$somecontent) === FALSE) {
           echo 
    "Cannot write to file ($filename)";
           exit;
       }
       
       echo 
    "Success, wrote ($somecontent) to file ($filename)";
       
       
    fclose($handle);

    } else {
       echo 
    "The file $filename is not writable";
    }
    ?>
    do you guys see anything wrong? im trying to get the word 'testline' to write to the file!

  11. #11
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: question

    u need a semicolon here... $somecontent = $_GET['txt'] so it should be... $somecontent = $_GET['txt'] ;

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: question

    ok thanks it works beautifully. but 1 problem..

    when i do it twice, for e.g..

    wb.Navigate "http://localinfo/fwrite.php?txt=text1"
    wb.Navigate "http://localinfo/fwrite.php?txt=text1"

    it writes it to the textfile but its like this:

    text1text2

    isnt it possible to get it like

    text1
    text2

    ..in the text file?

  13. #13
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: question

    Add the newline character to the end of your string:
    PHP Code:
    $somecontent $_GET['txt'] . "\n"
    Good luck
    {yak}

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: question

    thanks for the reply but my text file is like this after i write to the file

    wb.Navigate "http://localinfo/fwrite.php?txt=text1"
    wb.Navigate "http://localinfo/fwrite.php?txt=text2"
    wb.Navigate "http://localinfo/fwrite.php?txt=text3"


    PHP Code:
    <html>
    <
    h1>Header</h1>
    text1<newlinecharhere>text2<newlinecharhere>text3
    </html
    and when i view it in explorer:

    http://localhost/test.txt

    it shows the header fine, but the words are stil like this:

    text1text2text3

  15. #15
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: question

    Did you add the "\n" onto the string?
    {yak}

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: question

    yep:

    $somecontent = $_GET['txt'] . "\n";

    it works without the html tag stuff, but i want to mae it work *with* the html tags so i can have a nice heading at the top of the text file when viewed through i.e

  17. #17
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: question

    So it's html? I'm kinda lost, but if it's html, then, add a break tag:
    <br>
    {yak}

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: question

    yep works, thanks alot!

Posting Permissions

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



Click Here to Expand Forum to Full Width