PDA

View Full Version : using txt files for content


shinko_metsuo
04-11-2005, 03:46 AM
I'm making a web site for a friend and I want to make it user friendly as possable. Here is what I have. I have an index.php witch is the page that I want to put the content on. I have a content.txt witch is what I'll have the content written to so I can use it in index.php. Then I have update.php this is the page that I want it where the user can put his content in and it will wirte to content.txt to display on the site.

I don't know how to write/get stuff from a txt file so how do I set this up?
I hope I did not confuse you

thanks advace,
Metsuo

amir
04-11-2005, 06:08 AM
Hi friend! H R U.
I m sending u very easy code to read and write a file.

//////////////////////////Reading File//////////////////////////////////////
<?php
$filename = "c:\\files\\urfile.txt";
$handle = fopen ($urfilename, "r");
$contents = fread ($handle, urfilesize ($urfilename));
fclose ($handle);
?>
////////////////////////////////////////////////////////////////////////////

//////////////////////////Writing File//////////////////////////////////////
<?php
$filename = 'test.txt';
$somecontent = "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
print "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (!fwrite($handle, $somecontent)) {
print "Cannot write to file ($filename)";
exit;
}

print "Success, wrote ($somecontent) to file ($filename)";

fclose($handle);

} else {
print "The file $filename is not writable";
}
?>
////////////////////////////////////////////////////////////////////////////

Regards,
Aamir.
Bye

Do not put off till tomorrow what u can do today!

shinko_metsuo
04-11-2005, 12:19 PM
Thanks I think I got everything down but the read

<?php
$filename = "c:\\files\\urfile.txt";
$handle = fopen ($urfilename, "r");
$contents = fread ($handle, urfilesize ($urfilename));
fclose ($handle);
?>

on urfilesize I just put a number in like
$contents = fread ($handle, 25445 ($urfilename));

I got a parse error not sure what to do.

shinko_metsuo
04-11-2005, 11:49 PM
ok nvm I got it I just had a little name mix up

thanks for all the help :thumbsup:
Metsuo

shinko_metsuo
04-12-2005, 12:15 AM
now I need help again.

I have a form set up to it so I thought

$somecontent = '$_GET["content"];';

would work but I litteraly writes $_GET["content"];

how do I fix that?

Kurashu
04-12-2005, 01:07 AM
$somecontent = $_GET["content"]

shinko_metsuo
04-12-2005, 01:20 AM
$somecontent = $_GET["content"]
I tried that and it did not write to it.