note 65025 added to function.file-put-contents

From: Date: Mon, 24 Apr 2006 11:46:48 +0000
Subject: note 65025 added to function.file-put-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-109386@lists.php.net to get a copy of this message
To use file_put_contents under PHP 4 you can use this <?php function file_put_contents($filename, $content, $flags = null, $resource_context = null) { if (is_array($content)) { $content = implode('', $content); } if (!is_scalar($content)) { user_error('file_put_contents() The 2nd parameter should be either a string or an array', E_USER_WARNING); return false; } $length = strlen($content); $mode = ($flags & FILE_APPEND) ? 'a' : 'w'; $use_inc_path = ($flags & FILE_USE_INCLUDE_PATH) ? true : false; if (($fh = @fopen($filename, $mode, $use_inc_path)) === false) { user_error('file_put_contents() failed to open stream: Permission denied', E_USER_WARNING); return false; } $bytes = 0; if (($bytes = @fwrite($fh, $content)) === false) { $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s', $length, $filename); user_error($errormsg, E_USER_WARNING); return false; } @fclose($fh); if ($bytes != $length) { $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.', $bytes, $length); user_error($errormsg, E_USER_WARNING); return false; } return $bytes; } ?> ---- Server IP: 217.13.201.10 Probable Submitter: 80.228.88.227 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.file-put-contents.php Edit -- http://master.php.net/note/edit/65025 Del: integrated -- http://master.php.net/note/delete/65025/integrated Del: useless -- http://master.php.net/note/delete/65025/useless Del: bad code -- http://master.php.net/note/delete/65025/bad+code Del: spam -- http://master.php.net/note/delete/65025/spam Del: non-english -- http://master.php.net/note/delete/65025/non-english Del: in docs -- http://master.php.net/note/delete/65025/in+docs Del: other reasons-- http://master.php.net/note/delete/65025 Reject -- http://master.php.net/note/reject/65025 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#109386) next »