how to Load Text file into HTML, inside tag?, I don't have an source to show you. thanks
如何将文本文件加载到HTML,内部标记?,我没有向您显示的来源。谢谢
1 个解决方案
#1
1
You can use PHP to load files from the user's computer. Here is an example.
您可以使用PHP从用户的计算机加载文件。这是一个例子。
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
确保将#textbox更改为textarea标记的ID。 (例如
#1
1
You can use PHP to load files from the user's computer. Here is an example.
您可以使用PHP从用户的计算机加载文件。这是一个例子。
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
确保将#textbox更改为textarea标记的ID。 (例如