- fclose: documentation ( source)
- fwrite: documentation ( source)
- fopen: documentation ( source)
- is_writable: documentation ( source)
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?PHP
$filename = 'text.txt';
$somecontent = "My name is Chukwudi and this is my contribution \n";
// Let's check if file exists and writable.
IF (IS_WRITABLE($filename)) {
// opening $filename.
// that's where $somecontent will go when we fwrite() it.
IF (!$handle = FOPEN($filename, 'a')) {
PRINT "Cannot open file ($filename)";
EXIT;
}
// Write $somecontent to text.txt 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";
}
?>
</body>
</html>