Results 1 to 3 of 3

Thread: writing to text file

  1. #1

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

    writing to text file

    i uploaded a text file called 'logs.txt' and write.php to a www folder on a server (i got a subdomain)

    so the links to these are like, E.G:.
    www.site-here.com/logs.txt
    www.site-here.com/write.php


    then why doesnt something like this work:

    www.site-here.com/write.php?txt=Hello

    and it should write the word 'Hello' to logs.txt

    Heres write.php..

    PHP Code:
    <?php
    $filename 
    'logs.txt';
    $somecontent $_GET['txt'] . "\n"

    if (
    is_writable($filename)) {

       if (!
    $handle fopen($filename'a')) {
             echo 
    "Cannot open file ($filename)";
             exit;
       }

       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";
    }
    ?>
    any help guys?

    i just keep getting: Cannot write to file logs.txt
    Last edited by Pouncer; Sep 19th, 2005 at 03:00 PM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: writing to text file

    Turn on error handling by adding this to the top of your script. This should tell you what error, if any is causing the script to fail.
    PHP Code:
    error_reporting(E_ALL); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    New Member
    Join Date
    Sep 2005
    Posts
    9

    Re: writing to text file

    Remember, I'm a n00b but....

    I think you need to make sure you give "logs.txt" write permissions to others.

    I got an error with this permissions:
    -rw-rw-r-- 1 user user 12 Sep 19 17:59 logs.txt

    Works fine with this permissions:
    -rw-rw-rw- 1 user user 12 Sep 19 17:59 logs.txt

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