Shazer2 Posted December 18, 2011 Share Posted December 18, 2011 I'm trying to write to a file with the following code. $fh = fopen("../inc/config.php", "a") or die("\r\nCan't open file."); $write = "\$config['database_host'] = {$mysqlh}; \$config['database_user'] = {$mysqlu}; \$config['datbase_pass'] = {$mysqlp}; \$config['datbase_name'] = {$dbn}; \$config['table_prefix'] = {$tp};"; fwrite($fh, $write); fclose($fh); It is printing out "Can't open file", which I guess means it can't find the file or I've given the wrong path. The file that is executing this code is /install and the file I'm trying to write to is /inc/config.php. I thought .. put you up a directory so if I do .. I will be at the root and then do /inc I will be in inc. Can someone please guide me on what I'm doing wrong? Thanks. Link to comment https://forums.phpfreaks.com/topic/253414-writing-to-a-file/ Share on other sites More sharing options...
SergeiSS Posted December 18, 2011 Share Posted December 18, 2011 I just checked your code - it works fine at my localhost. In my case I am at /test and create a file in /tmp. Do you have this directory '/inc'? If you have it maybe that you don't have a permission to write. Link to comment https://forums.phpfreaks.com/topic/253414-writing-to-a-file/#findComment-1298984 Share on other sites More sharing options...
Shazer2 Posted December 18, 2011 Author Share Posted December 18, 2011 Thanks SergeiSS, I had to CHMOD to 666 to write to it. Thanks. Link to comment https://forums.phpfreaks.com/topic/253414-writing-to-a-file/#findComment-1298985 Share on other sites More sharing options...
SergeiSS Posted December 18, 2011 Share Posted December 18, 2011 Thanks SergeiSS You are welcome Link to comment https://forums.phpfreaks.com/topic/253414-writing-to-a-file/#findComment-1298986 Share on other sites More sharing options...
manny Posted December 18, 2011 Share Posted December 18, 2011 i would reccomend utilizing the absolute paths, so that it works for almost any server config... Works like a charm for me. <?php $fh = fopen(dirname(dirname(__FILE__))."/inc/config.php", "a") or die("\r\nCan't open file."); $write = "\$config['database_host'] = {$mysqlh}; \$config['database_user'] = {$mysqlu}; \$config['datbase_pass'] = {$mysqlp}; \$config['datbase_name'] = {$dbn}; \$config['table_prefix'] = {$tp};"; fwrite($fh, $write); fclose($fh); ?> Link to comment https://forums.phpfreaks.com/topic/253414-writing-to-a-file/#findComment-1299018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.