שלום לכולם.
אני מנסה לערוך קובץ וכשאני מנסה לקרוא אותו אני מקבל את השגיאה הבאה:
Warning: fread() [function.fread]: Length parameter must be greater than 0
הנה הקוד, הבעיה היא בשורה 36:
PHP קוד:
<center>
<h1>Uploading a file:</h1>
<form action="<?php echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data">
Upload file: <input type="file" name="my_file"/>
<br/>
<input type="submit" name="upload_file" value="Upload file!">
</form>
<br>
<h2>Open a file:</h2>
<form method="post">
<tr>
<td><gb>Name of the file to open:</gb></td>
<td><input type=text name="file" value="test.txt"></td>
</tr>
<tr>
<input type="submit" name="open_file" value="Open file!">
</form>
<br>
</center>
<?php
if(isset($_POST['upload_file'])) {
if (!empty($_FILES["my_file"]["name"])) {
$dir = getcwd()."/files/";
move_uploaded_file($_FILES["my_file"]["tmp_name"] , $dir.$_FILES["my_file"]["name"]);
echo "<center><b>Message:</b></center>";
echo "<center>The file was uploaded!</center>";
}
else {
echo "<center><b>Error:</b></center>";
echo "<center>Falied to upload the file!</center>";
}
}
if(isset($_POST['open_file'])) {
echo "<center>Editing the file:<b>{$_POST['file']}</b></center>";
$file_open = fopen("files/{$_POST['file']}", "wb");
$text = fread($file_open, filesize("files/{$_POST['file']}"));
$br_text = str_replace("\n", "<BR>", $text);
echo "<center><tr><td><textarea rows='20' name='edit_area' cols='50' value='{$br_text}'></textarea></tr></td></center>";
echo "<center><tr><td><input type='submit' name='edit_file' value='Edit file!'></tr></td></center>";
if(isset($_POST['edit_file'])) {
fwrite($file_open, $_POST["edit_area"]);
echo "<center><b>Message:</b></center>";
echo "<center>Succsess to edit the file!</center>";
}
fclose($file_open);
}
?>