Source for file file_put_contents.php
Documentation is available at file_put_contents.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Aidan Lister <aidan@php.net> |
// +----------------------------------------------------------------------+
// $Id: file_put_contents.php,v 1.23 2005/01/26 04:55:13 aidan Exp $
if (!defined('FILE_USE_INCLUDE_PATH')) {
define('FILE_USE_INCLUDE_PATH', 1 );
* Replace file_put_contents()
* @link http://php.net/function.file_put_contents
* @author Aidan Lister <aidan@php.net>
* @version $Revision: 1.23 $
* @internal resource_context is not supported
* @require PHP 4.0.0 (user_error)
function file_put_contents($filename, $content, $flags = null , $resource_context = null )
// 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 date 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',
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.',
Documentation generated on Mon, 11 Mar 2019 14:20:35 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|