Page 1 of 1

open a file with php

Posted: Tue Jan 03, 2012 5:05 pm
by mck.workman
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>");
}
?>

Re: open a file with php

Posted: Tue Jan 03, 2012 7:26 pm
by twinedev
If you get actual PHP source code showing in a browser, then the server is not set to handle the page you called as a PHP script. Does it have the correct extension (usually .php)?

But however, as you can see (and I noticed when I took a second look) that the PHP code is not highlighted differently here like it is higher up in the code... Reason why? You do not have a proper opening tag, you have <$php instead of <?php

-Greg