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

时间:2015-06-12 10:00:37

标签: php html

任务是从名为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>";

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

1 个答案:

答案 0 :(得分:0)

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