November 19th, 2000, 11:19 AM
What i am trying to do is have a form which allows users to submit a news story to my sites archives. They have to enter the title, their name and the story itself. When they click submit i want my PHP script to create a new text file (using fopen()???) and the data to be written to it.
My problem is that when I use fopen() i can't get it to create a new file. I read the manual and i think it said to use:
fopen("file.txt", "a+"); to create a new file if file.txt doesnt exist.
But i cant get it to work. Can anyone tell me the correct syntax???
And also, when I do this:
$stuff = readfile("File.txt");
why do i get the number of characters in the file appearing at the end?
November 19th, 2000, 02:04 PM
to create the new file use:
Low Cost Hosting and Web Development.
November 20th, 2000, 03:06 AM
Also make sure your permissions are set correctly.
November 20th, 2000, 04:04 AM
Regarding your readfile() problem...
Firstly, read the manual page for readfile() (here.)
Then once you've read that you'll see the bit that says that readfile() returns the number of bytes in the file that is being read. I think what you're problem is is that you don't realise that when you go:
$stuff = readfile(bla bla bla);
it's not actually reading the file into $stuff, it's outputting the file.
then, because you have the line that goes:
It's just tacking the number of bytes in the file onto the end.
Hope that helps,
November 20th, 2000, 06:12 AM
This should do the trick for reading out your .txt file
$filename = "file.txt";
$stuff = file($filename);
for($i=0 ; $i < count($stuff) ; $i++)
Until next time, I'll Remain!!
Quote the Dokus:"NeverMore!"
November 20th, 2000, 06:20 AM
Even better is this: (sorry, had to do it Dokus)
November 20th, 2000, 01:05 PM
Thanks for your help guys, i had figured out Dukus' method myself yesterday, but thanks anyway!
Also, Sepodati - WHat does the implode function do exactly? I have seen implode() mentioned in another post, but i dont know what it does (havent checked the manual yet)
November 20th, 2000, 03:11 PM
awe come one... what's wrong with readfile?
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>readfile('myfile.txt');[/code]
November 20th, 2000, 03:52 PM
Since this is a contest of sorts (just kidding) then here is one way to do it...... i would not do it this way..... (i personally liek the readfile() way) but here are my two cents::
hehe ..... well it diplays the contents....
November 20th, 2000, 10:33 PM
readfile() is the easiest, if you don't need the file actually assigned to a variable.