Search code examples
phpwarningswritetofile

PHP Config.php for write to flat file


The php code grabs values from a form and writes it to flat file. 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.

error1: states that there is no config.php

error2:I have to specify a path but if

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

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

Solution

  • You have 2 ways: create config.php or remove include.