Jump to content


Photo

Im pretty sure this is PHP...


  • Please log in to reply
5 replies to this topic

#1 Imtehbegginer

Imtehbegginer
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 20 September 2006 - 12:02 AM

Everyone knows about the f functions.
fopen
fwrite
fclose

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

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 20 September 2006 - 12:10 AM

I belive php has already done this for you

http://es2.php.net/m...tion.fwrite.php

Tell me the problem, I will try tell you the solution

#3 Imtehbegginer

Imtehbegginer
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 20 September 2006 - 12:55 AM

Thanks alot :)

#4 Imtehbegginer

Imtehbegginer
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 20 September 2006 - 01:34 AM

:-\ It doesnt work, It just writes the whole script over again, and if it put $_POST['varname'] I get a huge error :S.

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 20 September 2006 - 01:38 AM

"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.
Legend has it that reading the manual never killed anyone.
My site

#6 Imtehbegginer

Imtehbegginer
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 20 September 2006 - 01:59 AM

<?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";
}
?>
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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users