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

时间:2013-05-21 00:23:41

标签: php warnings writetofile

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

error1:声明没有config.php

错误2:我必须指定一个路径,但是如果

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

任何帮助将不胜感激。

CODE:

<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>

ERROR:

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

2 个答案:

答案 0 :(得分:0)

您有两种方法:创建config.php或删除包含。

答案 1 :(得分:0)

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

 if (file_exists('config.php')) {
     include('config.php');
  }

http://php.net/manual/en/function.file-exists.php