The problem is that only first n number of characters are being saved back to the file when the user submits the form. Not sure exactly what n is but essentially after 20 lines or so (Or sometimes less), data is not being saved to the file.
The HTML form creation is pretty simply. First I read from the file.
Code: Select all
<?php
$filename = "../scripts/$file";
$fp=fopen($filename,"r");
while (!feof ($fp)) {
$buffer = $buffer . fgets($fp, 4096);
}
$file_data=$buffer;
fclose ($fp);
?>Code: Select all
<form action="this.php" method="post">
<textarea name="file_data">
<?php print $file_data;?>
</textarea>
<input type="submit">
</form>Code: Select all
$filename = "../scripts/$file";
$filesize=filesize($filename);
$file_data=stripslashes($file_data);
if (is_writable($filename)) {
if (!$fp = fopen($filename, "w")) {
print "Cannot open file ($filename)";
exit;
}
if (!fwrite($fp, $file_data, $filesize)) {
print "Cannot write to file ($filename)";
exit;
}
print "Success, wrote to file ($file)<p>";
fclose($fp);
} else {
print "The file $filename is not writable";
}How can I write all of the contents from the form to the file? Is there something special that needs to be done with the fwrite() function when running on a Unix file system? Do I need to write to the file line by line?