note 49705 deleted from function.file-put-contents by aidan

From: Date: Mon, 14 Feb 2005 05:16:10 +0000
Subject: note 49705 deleted from function.file-put-contents by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-84992@lists.php.net to get a copy of this message
Note Submitter: codeslinger at compsalot dot com ---- <?php /********************************* This is a substitue for file_put_contents which is only available on PHP5 We pass the data by ref to avoid memory duplication of possibly large values per the spec, arrays are converted as join('', $array) int file_put_contents ( string filename, mixed data [, int flags [, resource context]] ) Any functions which are conditionally defined must appear before they are used. Caution: This does not do File Locking... Tested on PHP 4.3.10; not tested and may not work on PHP 3 I have not tested the $Context, although fopen doesn't complain, it may not support it. Written by codeslinger@compsalot.com 2/3/2005 Released to the public domain *********************************/ // Define Flags for the function // Note: These Values are arbitrary, I don't have access to PHP5 to see what they really are. if (! defined('FILE_USE_INCLUDE_PATH')) define('FILE_USE_INCLUDE_PATH', 2); if (! defined('FILE_APPEND')) define('FILE_APPEND', 4); if (! function_exists('file_put_contents')) { function file_put_contents($strFileName, &$MixedData, $Flags = 0, $Context = NULL ){ if (is_null($Context)){ $fp = fopen($strFileName, ($Flags & FILE_APPEND) ? "ab" : "wb", $Flags & FILE_USE_INCLUDE_PATH ); } else { $fp = fopen($strFileName, ($Flags & FILE_APPEND) ? "ab" : "wb", $Flags & FILE_USE_INCLUDE_PATH, $Context ); } if ($fp === FALSE){ //Error... return(FALSE); } if (is_array($MixedData)){ $Result = fwrite($fp, join('', $MixedData)); } else { $Result = fwrite($fp, $MixedData); } fclose($fp); return($Result); } } ?>

« previous php.notes (#84992) next »