note 38237 deleted from function.fwrite by irchtml

From: Date: Mon, 23 Feb 2004 07:52:55 +0000
Subject: note 38237 deleted from function.fwrite by irchtml
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65564@lists.php.net to get a copy of this message
Note Submitter: Graham ---- <?php $filename = "example.txt"; if (!$handle = fopen($filename, 'a')) { print "Cannot open file ($file)"; exit; } $somecontent = "Hello"; if(is_writable($file)){ if (!fwrite($handle, $somecontent)) { print "Cannot write to file ($file)"; exit; } } else { chmod ($file , 0777) or die ("I found out you couldn't write to the file so I tried to chmod it but it didn't work"); echo "Please refresh the page"; } ?> That example will write hello to example.txt if example.txt is writable, otherwise it will chmod and ask the user to refresh so it can try again. I know the code is a bit tatty at being presented but I am not very good at that.

« previous php.notes (#65564) next »