Source for file file_put_contents.php
Documentation is available at file_put_contents.php
// $Id: file_put_contents.php,v 1.27 2007/04/17 10:09:56 arpad Exp $
if (!defined('FILE_USE_INCLUDE_PATH')) {
define('FILE_USE_INCLUDE_PATH', 1 );
* Replace file_put_contents()
* @license LGPL - http://www.gnu.org/licenses/lgpl.html
* @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
* @link http://php.net/function.file_put_contents
* @author Aidan Lister <aidan@php.net>
* @version $Revision: 1.27 $
* @internal resource_context is not supported
* @require PHP 4.0.0 (user_error)
// If $content is an array, convert it to a string
// If we don't have a string, throw an error
user_error('file_put_contents() The 2nd parameter should be either a string or an array',
// Get the length of data to write
// Check what mode we are using
// Check if we're using the include path
// Open the file for writing
if (($fh = @fopen($filename, $mode, $use_inc_path)) === false ) {
user_error('file_put_contents() failed to open stream: Permission denied',
// Attempt to get an exclusive lock
$use_lock = ($flags & LOCK_EX) ? true : false ;
if ($use_lock === true ) {
if (($bytes = @fwrite($fh, $content)) === false ) {
$errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s',
// Check all the data was written
$errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.',
function file_put_contents($filename, $content, $flags = null , $resource_context = null )
Documentation generated on Mon, 11 Mar 2019 15:26:35 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|