User Contributed Notes: fwrite
otterley
10-Nov-1999 05:35
What's the return value supposed to indicate?
joss@ja.ee
26-Nov-1999 12:26
When I try to write to the end of the file it doesn't.
I made a file which writes 25 bytes to the end of the file, but when I reload
the page, then it just rewrites the same place.
Here's my file:
<pre>
<?
$html_fail = "kirjutamis_fail.txt";
$fp = fopen( $html_fail,"a+");
$k_hulk = 26;
printf(" kirjutamine: %d", fwrite( $fp, "12345678901234567890123456", $k_hulk) );
fclose($fp);
?>
</pre>
joss@ja.ee
26-Nov-1999 06:01
My mistake, I'm really sorry.
I used "w+" and that truncated file to 0 size.
Again, sorry
hhac@hotmail.com
16-Dec-1999 01:01
Here is a hit counter function that opens a file, reads in the value, increments it and writes it out back to the file. It doesn't do synchronization though :)
<PRE>
<?
function IncrementHitCounter($filename)
{
// $filename is the name of the file with an integer value
// The file must have global write permisions on it (chmod 666 filename)
$counterval = 0;
$fp = fopen( $filename,"r");
$counterval = fread($fp, 26 );
fclose( $fp );
$counterval = (integer)$counterval + 1;
$fp = fopen( $filename,"w+");
fwrite( $fp, $counterval, 26);
fclose( $fp );
echo "$counterval hits on this page.";
}
?>
</PRE>
zhilin@188.net
19-Dec-1999 01:05
add a new line in a file end:
<PRE>$fp=fopen($filename, 'a+');
fwrite($fp,"$str \n");
fclose($fp);</PRE>
is all
dave@eiremap.ie
21-Jan-2000 11:35
use stripSlashes(), that will remove
the slashes from your output.
randy@intelliweb.com.my
14-Feb-2000 07:34
I have problem using fwrite or fputs,
it just doesn't write to the file. However it'll empty the file when I use
"w" of "w+", and nothing happenned
when "a+" or "r+" are used. Ugh...
pimou@delyth.net
21-Feb-2000 01:07
I had the same results using fputs and fwrite! :/
aakash_kambuj@hotmail.com
11-Mar-2000 07:00
Can fwrite be used to write binary data to the browser ?
For example, if i want to send an EXE file to the user, how would i use binary-safe writing?
Thanks,
aakash
wilco@knot.nl
12-Mar-2000 10:46
Is it possible to set the file pointer at the beginning of the file and
INSERT data/text in the file without overwriting the data/text that's already there??
gregk@wwwpages.com
12-Mar-2000 06:59
Im having the same problem with data not being output to the file I specify with an fwrite
emerson@kieser.net
20-Mar-2000 10:51
Had the same problems with fwrite. A fix seems to be to convert the datafile to unix format. So if you read it using a windows editor(those using samba) convert it back to unix format. It works.
ma701mp@gold.ac.uk
29-Mar-2000 09:51
I am running an HTML page, it contains a form, I want to output the submitted data into a text file. I want to store the file on a Unix server.
I'm trying to write to the file "comments.txt". However, the script is not writing to the source. I have catered for the "nobody" owner access previleges. I have set the permissions correctly. I have pointed the script through an HTML form. I don't know what the problem is, help :(
<?php
$myfile = fopen("public_html/comments/comments.txt", "a+");
if ($comments.txt)
{
fputs ($myfile, "Date: $date1\n");
fputs ($myfile, "Channel: $channel\n");
fputs ($myfile, "-----------------------\n");
}
fclose ($myfile);
?>
flash@drewnels.et
13-Apr-2000 02:05
Does anyone know how to write to at the current pointer position rather than at the beginning or end of the file?
flash@drewnels.net
13-Apr-2000 02:08
Does anyone know how to write to at the current pointer position rather than at the beginning or end of the file?
cream@donut.dk
09-Jul-2000 04:06
I have a small problem, when add some text (submitted from a normal textarea form) all " and ' gets a \ put infront of them, i use this small simple code to add to the file:
$mainupdate = fopen("../index.inc", "a+"); fputs $mainupdate, "$txtPageText"); fclose($mainupdate);
rich@csmicros.com
10-Jul-2000 06:16
I am simply trying to copy the contents of text boxed to a line in a text file. When 'submit' is clicked, a text file is opened, the text box contents added to the top/bottom of the text file. However, my code does not seem to write anything into the text file! Help!! My code is shown below.
<?php
$file=fopen("http://support.intanames.co.uk/list.txt","a");
fwrite($file, "Write text here like this: $name\n");
fclose($file);
?>
Any ideas?? rich@csmicros.com
penetrator@europe.com
13-Jul-2000 04:50
HELP ME! I open a file, and simply want to write something in the file on a new line. My code:
$fp = fopen ($filename, "a+");
fwrite ($fp, "$str \n");
fclose ($fp);
Please help me.
penetrator@europe.com
14-Jul-2000 01:41
I HAVE SOLVED THE PROBLEM INSERTING AN ENTER IN TO A FILE. To write a return in a file, use \r\n. Example: fwrite($fp,"$str \r\n");
penetrator@europe.com
14-Jul-2000 01:41
I HAVE SOLVED THE PROBLEM INSERTING AN ENTER IN TO A FILE. To write a return in a file, use \r\n. Example: fwrite($fp,"$str \r\n");
info@sitelinktech.com
27-Jul-2000 10:52
I am trying to dynamically write the contents of a string that includes variables to a new file using FPUTS(). It works fine the first time after starting my browser, but each subsequent execution of the script results in the same string being written to the file regardless of the variable setting. It appears to cache the string data in FPUTS() for some reason. If I stop and restart my browser and run the script again it only works correcty the first time. I have tried loading the html header settings to turn of page caching but that doesn't help. Here is a sample of the script.
$fp = fopen($dest_path.$userid.".txt", "w");
fputs($fp, "http://".$server.$web_path.$new_file.".htm");
fclose($fp);
Any ideas what I am doing wrong?
info@sitelinktech.com
28-Jul-2000 06:51
The "caching" problem described above when trying to execute a script using FPUTS() after the first successful execution turned out to be a browser specific problem with IE version 4.72.3110. IE 5.x and Netscape 4.6 appear to work fine.
masquedroga@zipmail.com.br
03-Aug-2000 07:29
Hey guys, fwrite() function is to use with binary files, for txt files use the fputs() function.
I´m trying to download a file from any http location and put all data into a local file. But it doesn't work, because the file downloaded is treated like a txt file or something. Example: I download a jpeg file whith fopen() and join it in an array with file() function, and when I put the data in a local file with fwrite(), it´s write like strings, not binary data. Help-me!