HTML Code:
<form class="form-horizontal" action="<?php echo htmlspecialchars($_SERVER[" PHP_SELF "]); ?>" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label class="col-sm-2 control-label">Write File</label>
<div class="col-sm-6">
<input type="file" class="form-control-file" id="fileToWrite" name="fileToWrite">
</div>
<div class="col-sm-6">
<textarea type="text" class="form-control" rows="5" name="write_file"></textarea>
</div>
<button type="submit" class="col-sm-2 btn btn-default">Write</button>
</div>
</form>
PHP Code:
<?php
if ("" != trim($_FILES['fileToWrite']["tmp_name"])) {
if (!file_exists($_FILES['fileToWrite']["tmp_name"])) {
echo "File named: <span style='color:red;'>" . $_POST['fileToWrite'] . "</span> doesn't exist! <br>";
} else {
$fw = fopen($_FILES['fileToWrite']["tmp_name"], "w");
fwrite($fw, $_POST['write_file']);
echo 'File over-written successfully';
}
}
?>
Output: File over-written successfully
Text File is stored at Desktop or any other place, php file is stored in htdocs. (It doesn't matter anyway)
I am taking input from user using textarea, and taking file to be edited using input type=file. After submitting, it shows successfull message, but doesn't make any change to file. Please help me out.