在php中显示html文件的内容[关闭]

Hi guys I want to create simple file system using php. I want to display content of uploaded file using php. But whene I upload html or php file then instead of showing its content, html or php code gets executed. I want to display that files without executing. Plz help me. Thank you.

If PHP get's executed you are including/requiring the file. Read it's contents instead, e.g. with file_get_contents()
To prevent the browser from parsing the HTML use htmlentities()

Example:

<?php
$filename = "test.html";
echo "<pre><code>";
echo htmlentities(file_get_contents($filename));
echo "</code></pre>";
?>

If you want to display the raw code, you can:

a) Make it a text file

or

b) use htmlentities() on the output

Shows the content of the file:

readfile($yourFilename);

If you don't want the browser to interpret your code, try and setting "wrong" MIME types.