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 4 of 4
  1. #1
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post

    Writing to a file in php

    guys isnt my code correct? there are no syntax errors. The code is ment to take input from a text field and write it to a dump.txt file. And display the file along with it if the file exists
    but its bugged.. it neither reads or writes
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <?php
    $file
    ='dump.txt';
    if(isset(
    $_POST['submit']))
    {
    $fo=fopen($file,'a') or die('File op error');
    fwrite($fo,$_POST['txt'].'<br />') or die('File op error');
    fclose($fo);
    }
    if(
    file_exists($file))
    {
    $read=file($file);
    echo 
    "Contents of the file DUMP are:<br /><br />";

    foreach(
    $read as $i)
    {
    echo 
    $i."<br />";
    }
    }
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF'?>" method="get">
    <input name="txt" type="text" value="Enter here" />
    <input name="submit" type="submit" value="submit" /></form>
    </body>
    </html>
    Last edited by adarshakb; 10-22-2009 at 03:51 PM.
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    do you have write permissions for the folder? also add this line above your php to make sure there are no errors.
    PHP Code:
    error_reporting(E_ALL); 

  • #3
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post
    Quote Originally Posted by ninnypants View Post
    do you have write permissions for the folder? also add this line above your php to make sure there are no errors.
    PHP Code:
    error_reporting(E_ALL); 
    i checked.. i could read the file if i gave absolute path changed to $file='C:\aduDocs\dump.txt'; but it is not able to write.
    I thought windows was not allowing access to c drive[ i use vista] and changed path to d:\dump.txt but still same problem

    Earlier i could read files with relative paths itself. So i am confused here
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs

  • #4
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post
    so how to change this strange vista behavior?
    Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.

    Albert Einstein
    -----------------------------------------------------
    My Blog songs


  •  

    Posting Permissions

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