...

View Full Version : Writing to a file in php



adarshakb
10-22-2009, 03:49 PM
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 :(

<!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>

ninnypants
10-22-2009, 04:00 PM
do you have write permissions for the folder? also add this line above your php to make sure there are no errors.

error_reporting(E_ALL);

adarshakb
10-22-2009, 04:15 PM
do you have write permissions for the folder? also add this line above your php to make sure there are no errors.

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

adarshakb
10-22-2009, 05:36 PM
so how to change this strange vista behavior?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum