PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
function file_write($filename, &$content) {
if (!is_writable($filename)) {
if (!chmod($filename, 0666)) {
echo "Cannot change the mode of file ($filename)";
exit;
};
}
if (!$fp = @fopen($filename, "w")) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($fp, $content) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
if (!fclose($fp)) {
echo "Cannot close file ($filename)";
exit;
}
}
I've created a file called $filename in the directory where this script runs. It returns the error cannot change the mode file file_content.xml. I gave all the permissons possible on the file. But it still doesnt write.. What could be the problem
Well it's always good to know what you $_SERVER['DOCUMENT_ROOT'] is, so be sure to echo it to yourself first. I've found that it's the most effective way of getting filename's to work correctly.