简体   繁体   中英

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

The task is to browse a file from an HTML file named as upload.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>

And display the matching content of a browsed file into another page through upload.php . This file contains:

<?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>";

However it does not produce an output based on file ...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM