note 41194 added to function.is-writable

From: Date: Fri, 02 Apr 2004 09:56:18 +0000
Subject: note 41194 added to function.is-writable
Groups: php.notes 
Request: Send a blank email to php-notes+get-67509@lists.php.net to get a copy of this message
This file_write() function will give $filename the write permission before writing $content to it. Note that many servers do not allow file permissions to be changed by the PHP user. <?php function file_write($filename, &$content) { if (!is_writable($filename)) { if (!chmod($filename, 0666)) { echo "Cannot change the mode of file ($filename)"; exit; }; } if (!$fp = @fopen($filename, "w")) { echo "Cannot open file ($filename)"; exit; } if (fwrite($fp, $content) === FALSE) { echo "Cannot write to file ($filename)"; exit; } if (!fclose($fp)) { echo "Cannot close file ($filename)"; exit; } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.is-writable.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41194 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41194&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41194&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67509) next »