Imtehbegginer Posted September 20, 2006 Share Posted September 20, 2006 Everyone knows about the [b]f[/b] functions.fopenfwritefcloseCan anyone put together a small script, that will write to a file called config.php. Ill config everything else myself. Just a script that will open the file, write to it, and then close it. Please include a few text boxes. Link to comment https://forums.phpfreaks.com/topic/21336-im-pretty-sure-this-is-php/ Share on other sites More sharing options...
onlyican Posted September 20, 2006 Share Posted September 20, 2006 I belive php has already done this for youhttp://es2.php.net/manual/en/function.fwrite.php Link to comment https://forums.phpfreaks.com/topic/21336-im-pretty-sure-this-is-php/#findComment-94987 Share on other sites More sharing options...
Imtehbegginer Posted September 20, 2006 Author Share Posted September 20, 2006 Thanks alot :) Link to comment https://forums.phpfreaks.com/topic/21336-im-pretty-sure-this-is-php/#findComment-95000 Share on other sites More sharing options...
Imtehbegginer Posted September 20, 2006 Author Share Posted September 20, 2006 :-\ It doesnt work, It just writes the whole script over again, and if it put $_POST['varname'] I get a huge error :S. Link to comment https://forums.phpfreaks.com/topic/21336-im-pretty-sure-this-is-php/#findComment-95023 Share on other sites More sharing options...
AndyB Posted September 20, 2006 Share Posted September 20, 2006 "It doesn't work" and "huge error" really isn't going to be any help at all. We're not looking at what you wrote or what the error was. Perhaps if you post your code, someone will suggest functional improvements. Link to comment https://forums.phpfreaks.com/topic/21336-im-pretty-sure-this-is-php/#findComment-95024 Share on other sites More sharing options...
Imtehbegginer Posted September 20, 2006 Author Share Posted September 20, 2006 [code]<?php$filename = 'config.php';$somecontent = "<?PHP$databasehost = $databasehost?>";// Let's make sure the file exists and is writable first.if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle);} else { echo "The file $filename is not writable";}?> [/code]Install.php posts to this, that's where I get the $databasehost variable from.Now, when I try to write the $somecontent It writes the whole script. Dont I have to use $_POST['var'], if I use that, I get a different error. A while back, wildteen88 posted one for me. Link to comment https://forums.phpfreaks.com/topic/21336-im-pretty-sure-this-is-php/#findComment-95030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.