html5 - PHP fwrite() not writing anything to file, but no errors given -
i writing contents of html5 text area file on local server using php. have included checks fileexists, fileiswritable , fileisreadble , pass, no text appears in target file.
html
<form id = "notesform" action = "notes.php" method = "post"> <textarea id = "textarea" name = "text"></textarea> <button type="submit" value="save"> save</button> </form>
php
$filename = 'file://localhost/library/webserver/documents/notes/test.txt'; $somecontent = $_post["text"]; if (is_readable($filename)) { echo "<br />the file readable...<br />"; } else { echo "<br />the file not readable...<br />"; } if (is_writable($filename)) { echo "the file writable...<br />"; } else { echo "the file not writable...<br />"; } if (file_exists($filename)) { echo "file exists...<br />"; } else { echo "file cannot found...<br />"; } // make sure file exists , writable first. if (is_writable($filename)) { if (!$handle = fopen($filename, 'r')) { echo "cannot open file ($filename)"; exit; } // write $somecontent our opened file. if (fwrite($handle, $somecontent) === false) { echo "cannot write file ($filename)"; exit; } echo "success, wrote ($somecontent) file ($filename)"; fclose($handle); } else { echo "the file $filename not writable"; }
output:
file readable...
file writable...
file exists...
success, wrote ( gfnhfghgf) file (file://localhost/library/webserver/documents/notes/test.txt)
the file test.txt appears empty, can see problem is?
thanks
you opening file in readonly mode ('r').
try:
fopen($filename, 'w')
Comments
Post a Comment