open a file with php
Posted: Tue Jan 03, 2012 5:05 pm
I am trying to real simply display the contents of a file and am getting only the php code showing up on the web page but no errors or anything. Where does this mean the error is?
Code: Select all
<HTML>
<TITLE>Step 4</TITLE>
<HEAD>Pick a file to open and click "Display" to show its contents WITH PHP</HEAD>
<BODY>
<FORM ENCTYPE="multipart/form-data"METHOD="POST" ACTION="<?PHP echo $_SERVER['PHP_SELF'];?>">
<SELECT NAME="choice">
<OPTION>Components
<OPTION>Weights
</SELECT>
<BR><INPUT TYPE=submit NAME="Display" VALUE="Display">
</FORM></BODY>
</HTML>
<$PHP
$request = choice
if(isset($_POST['Display'])) {
echo "The form has been submitted and contents are below";
if($request = "Components") {
$file= fopen("files/components.txt", "r") or exit("Unable to open file");
}
if($request = "Weights") {
$file = fopen("files/weights.txt", "r") or exit("Unduble to open file");
}
while(!feof($file) { //if you were able to reach the end of the file with no errors
echo(fgets($file) . "<BR>");
}
?>