note 65025 deleted from function.file-put-contents by bjori
| From: | bjori@php.net | Date: | Mon, 24 Apr 2006 11:54:17 +0000 |
| Subject: | note 65025 deleted from function.file-put-contents by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109389@lists.php.net to get a copy of this message | ||
Note Submitter: Sonnenstrahl
Reason: in docs
----
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;
}
?>