I'm a beginner of php and am experiencing a weird problem of php code not working on localhost (open the index.php with Chrome on disk D) but working on web server. Here is my index.php. I searched for solutions but do not find one.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<p><?php echo "Success"; ?></p>
<p>Welcome! This is my personal webpage. </p>
<p style="color:red">This is a red font. </p>
<a href="subpage1.html"><p>Link</p></a>
<p><?php
$file = 'people.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= "John Smith\n";
// Write the contents back to the file
print file_put_contents($file, $current);
echo "finished";
?></p>
</body>
</html>
The style.css
is just some basic formatting of <h1>
and <p>
.
In addition, there is a person.txt
file on the same directory with index.php
.
So on localhost, Chrome browser does NOT print "Success", update my person.txt
, or print "finished". However, when I upload the index.php
, person.txt
, and style.css
to my web server using ftp, all the php codes are working. Can anyone help me on this?
P.S. The website is here.