【发布时间】:2018-06-22 16:22:56
【问题描述】:
我对 html/css 也很熟悉 php,而且我的英语很差.. 所以,我的问题...,我有这个来自here 的编解码器。我有三个文件,第一个是 index.php
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<form action="" method="POST">
<label>Name:
<input type="text" name="Name" class="Input" style="width: 225px" required>
</label>
<br><br>
<label> Comment: <br>
<textarea name="Comment" class="Input" style="width: 300px" required> </textarea>
</label>
<br><br>
<input type="submit" name="Submit" value="Submit Comment" class="Submit">
</form>
</body>
</html>
<?php
if($_POST['Submit']){
$Name = $_POST['Name'];
$Comment = $_POST['Comment'];
#Get old comments
$old = fopen("comments.txt", "r+");
$old_comments = fread($old, 1024);
#Delete everything, write down new and old comments
$write = fopen("comments.txt", "w+");
$string = "<b>".$Name."</b><br>".$Comment."<br>\n".$old_comments;
fwrite($write, $string);
fclose($write);
fclose($old);
}
#Read comments
$read = fopen("comments.txt", "r+");
echo "<br><br>Comments<hr>".fread($read, 1024);
fclose($read);
?>
比一个 style.css 文件和一个名为 cmets.txt 的空文件。这个文件我必须到一台计算机(computer A),用 apache 启动它,/etc/init.d/apache2 restart。在另一台计算机(计算机 B)我写信给浏览器,192.345.345.100/index.php,在 Name 我写我的名字并在 Comment ,评论..,什么都没有......。图片来自我的浏览器enter image description here,请任何人帮助我,谢谢!
来自计算机 B 的图像,在浏览器中写入 http://192.345.345.100/info.php ,我必须使用 <?php phpinfo(); ?> 构建的 info.php。
查看堆栈跟踪:
【问题讨论】:
-
我从未见过
fopen的t选项。我只会使用file_get_contents和file_put_contents。他们要容易得多。不过,DB 会是更好的方法。 -
图像看起来你没有安装 PHP。
-
感谢您的回答! ,对不起,但我很新,我不明白 file_get_contents ,你能举个例子吗....
-
php.net 是寻找答案的好地方php.net/manual/en/function.file-get-contents.php 和php.net/manual/en/function.file-put-contents.php 在您运行 PHP 之后。它们将替换您的
fopen、fread、fwrite和fclose。