|
First of all, you should never be writing to a PHP script.
You are allowing someone to write PHP coding into your website.
What if I wrote some PHP scripting to delete all of your files?
You write to either text files, or a database of some kind. You
write content that will be put into a web page (or script).
Here is a correct example:
$data="This is a paragraph of the content that I want to write into the file";
$myFile = "mycontent.txt";
$file = fopen($myFile, 'w+') or die("can't open file");
fwrite($file, $data);
fclose($file);
In most cases, you will be appending to a file, not overwriting a file.
The difference is this:
$file = fopen($myFile, 'a+') or die("can't open file");
The plus (+) sign means to create the file if it doesn't already exist.
Also, any files must have the proper CHMOD permissions to write to them.
Any data written is sanitized .. all PHP and HTML removed.
Then, you include that file on your website.
<?php include("mycontent.txt");?>
The data file will be inserted where it is included.
.
Last edited by mlseim; 09-24-2011 at 04:54 PM..
|