简体   繁体   English

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

[英]PHP Config.php for write to flat file

The php code grabs values from a form and writes it to flat file. php代码从表单中获取值并将其写入平面文件。 This code works locally but when I place it on the host I get the the two errors. 该代码在本地工作,但是当我将其放置在主机上时,会出现两个错误。 Local instance doesn't require a config.php in the directory but the host file does. 本地实例在目录中不需要config.php,但主机文件则需要。

error1: states that there is no config.php 错误1:指出没有config.php

error2:I have to specify a path but if 错误2:我必须指定路径,但是如果

? - what do I put in the config file so it allows me to create the flat file or can I reference the file same how?? -我应该在配置文件中放些什么,以便它允许我创建平面文件,或者可以相同的方式引用该文件?

any help would be appreciated. 任何帮助,将不胜感激。

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 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 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种方法:创建config.php或删除包含。

Are you sure the config.php file is in the right directory you can check if the file exist and then include like this 您确定config.php文件位于正确的目录中,可以检查该文件是否存在,然后像这样包含

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM