从一个页面浏览文件,并将其内容显示在另一个页面中


Browse a file from one page and display its contents into another page

任务是从名为 upload.html 的 HTML 文件中浏览文件

<html>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="my-file" size="50" maxlength="25"> <br>
<input type="submit" name="upload" value="Upload"></form></body>

并通过upload.php将浏览文件的匹配内容显示到另一个页面中。此文件包含:

<?php
if (is_uploaded_file($_FILES['my-file']['tmp_name']) && $_FILES['my-file']['error']==0) {
     echo "The file was uploaded successfully but has not been saved.<br>";
     echo "The file is temporarily stored: " . $_FILES['my-file']['tmp_name'] . "<br>";
     echo "The file name was: " . $_FILES['my-file']['name'] . "<br>";
     echo "The file type is: " . $_FILES['my-file']['type'] . "<br>";
   } else {
     echo "(Error Code:" . $_FILES['my-file']['error'] . ")";
}

$file = $_FILES['my-file'];
$out = file_get_contents($file);
$delimiter = '#';
$startTag0= '#';
$endTag0='freq';
$regex0 = $delimiter . preg_quote($startTag0, $delimiter) 
                . '(.*?)' 
                . preg_quote($endTag0, $delimiter) 
                . $delimiter 
                . 's';
preg_match($regex0,$out,$matches);
$match0 = $matches[0]."<br>";
echo "<pre>".$match0."</pre>";

但是,它不会产生基于文件的输出...

你需要使用include ('browse.html');