I read many of the other questions on this site revolving around this error, none of which were able to help me, The below php code takes the data input from the html file and sends it to the php file, after printing "Hello Name" on the page, it should open a file called My_file.txt, which is already created, and write to it, I have been unable to do so, any help would be great, here is my code:
index.html file:
<html>
<head><title>Hello Friend</title></head>
<body bgcolor="black">
<p style="text-align:center">
<font color="white">
<form action="data.php" method="post">
<input type="text" name="myname" id="myname">
<input type="submit" value="Submit">
</form>
</body>
</html>
data.php file:
<html>
<head>
<title>Hello Friend, this is php</title>
</head>
<body bgcolor="black">
<font color="white">
<code>
<?php
$name = $_POST["myname"];
echo "Hello, " . $name;
$filename = "My_file.txt";
chmod($filename, 777);
$f = fopen($filename, "w") or die("Unable to open file");
fwrite($f, "The Name is: " . $name);
f.close($f);
echo fgets($f);
fclose($f);
?>
Output:
Hello, JohnUnable to open file
答案 0 :(得分:0)
您想要打开文件进行写入。确保文件可以通过此php进程写入。检查出现data.php的脚本文件夹中的http服务器权限。同时启用更详细的php错误,这可能与很多事情有关(也许你的托管禁用了fopen功能)。