fwrite() doesnt always work

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NewbiePHP
Forum Newbie
Posts: 4
Joined: Tue Jan 10, 2006 8:39 am

fwrite() doesnt always work

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

"r+" is reading with appending.

use "wt" (writing in text mode)
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

shouldn't you open the file with "w" not "r+"
NewbiePHP
Forum Newbie
Posts: 4
Joined: Tue Jan 10, 2006 8:39 am

Post 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

;

:

#

~

}

{
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

play around with "t" (text) modifier
Post Reply