Page 1 of 1

fwrite() doesnt always work

Posted: Thu Jan 12, 2006 8:49 am
by NewbiePHP
i am opening a file in a textarea and people can edit it and save it..
its work fine adding stuff to the file and saving it..

BUT if i delete stuff from the fiel and save it it doesnt do it!.. why?
cause the file size is smaller? less data in it??

heres the code i have written

$FilePath = $_POST['Path'];
$FileData = $_POST['filedata'];


$SortedData = stripslashes($FileData);



$FileName = $FilePath;
$FilePointer = fopen($FileName, "r+");
fwrite ($FilePointer, $SortedData);

fclose($FilePointer);

cheer all

Posted: Thu Jan 12, 2006 8:52 am
by feyd
"r+" is reading with appending.

use "wt" (writing in text mode)

Posted: Thu Jan 12, 2006 8:53 am
by JayBird
shouldn't you open the file with "w" not "r+"

Posted: Thu Jan 12, 2006 8:57 am
by NewbiePHP
cool that works... but now its adding spaces between each line of code.

i had

;
:
#
~
}
{

and then more spaces between them after i edit the file eg below

;

:

#

~

}

{

Posted: Thu Jan 12, 2006 10:00 am
by shiznatix
what is this posted data you are writing? you sure it does not contain any of those chars? echo it out first and see what it is.

Posted: Thu Jan 12, 2006 10:21 am
by Weirdan
play around with "t" (text) modifier