SchoolforDesign
SchoolforDesign

Reputation: 455

how to Load Text file into HTML, inside <textarea> tag?

how to Load Text file into HTML, inside tag?, I don't have an source to show you. thanks

Upvotes: 3

Views: 1286

Answers (1)

FoxInFlame
FoxInFlame

Reputation: 950

You can use PHP to load files from the user's computer. Here is an example.

form.html

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

upload.php

<?php
$target_dir = "uploads/";  
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
        header("Location: http://example.com/displaymessage.php?filename=" + basename( $_FILES["fileToUpload"]["name"]));
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>

displaymessage.php

<?php
$file = $_GET['filename'];
?>
<script>
var client = new XMLHttpRequest();
client.open('GET', '/uploads/<?=$file?>');
client.onreadystatechange = function() {
  document.getElementById("#textbox").value = client.responseText;
}
client.send();
</script>

Make sure to change #textbox, to the ID of the textarea tag. (e.g. <textarea id="foo">) NOTE: I just came up with half of this code, and I am not sure if it will work

Upvotes: 1

Related Questions