我使用此代码上传文本文件
<?php
if(isset($_POST['submit'])){
$name = $_FILES["file"]["name"];
$tmp_name = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];
if (isset ($name)) {
if (!empty($name)) {
$location = 'C:/inetpub/wwwroot/';
if (move_uploaded_file($tmp_name, $location.$name)){
echo 'File Uploaded';
}
} else {
echo 'please choose a file';
}
}
}
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="submit" name="submit" value="Submit">
</form>
然后我有这个代码来逐行读取文件的内容
<?php
$lines = file ('the_name_of_file.txt');
foreach ($lines as $name){
echo "$name <br>";
}
?>
如何使用第二个代码从上传的文件中读取?
答案 0 :(得分:0)
要从已上传的文件中读取,您需要从上传的目录中读取。
<?php
$location = 'C:/inetpub/wwwroot/';
$lines = file($location . 'the_name_of_file.txt');
foreach ($lines as $name) {
// Code here
}
?>
答案 1 :(得分:0)
if (move_uploaded_file($tmp_name, $location.$name)){
$lines = file ($location.$name);
foreach ($lines as $name){
echo "$name <br>";
}
}