PHP Config.php用于写入平面文件



php代码从表单中获取值并将其写入平面文件。这段代码在本地工作,但当我把它放在主机上时,我得到了两个错误。本地实例不需要目录中的config.php,但主机文件需要。

error1:表示没有config.php

error2:我必须指定一个路径,但是如果

?-我在配置文件中放入什么,以便它允许我创建平面文件,或者我可以引用文件相同的方式?

任何帮助都将是感激的。

代码:

<html>
<head>
<title>test</title>
</head>
<body>
<?php 
include('config.php');
$user = $_GET["name"]; 
$message = $_GET["message"];
print("<b>Thank You!</b><br />Your information has been added! You can see it by <a href=savedinfo.php>Clicking Here</a>");
$out = fopen( $_SERVER['DOCUMENT_ROOT'] . '/flatfile/test/' . $user . '.txt', "a" );
if (!$out) { 
print("Could not append to file"); 
exit; 
} 
fputs ($out,implode,("n")); 
fwrite($out,"<b>$user</b><br />$message<br /><br />");
fclose($out);
?>
</body>
</html>
错误:

1

Warning: include(config.php) [function.include]: failed to open stream: No such file or directory in /home/user1/flatfile/sendinfo.php on line 7
2

Warning: include() [function.include]: Failed opening 'config.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/user1/flatfile/sendinfo.php on line 7

您有两种方法:创建config.php或删除include.

您确定config.php文件在正确的目录下您可以检查该文件是否存在,然后像这样包含

 if (file_exists('config.php')) {
     include('config.php');
  }
http://php.net/manual/en/function.file-exists.php

最新更新