Annotation of /mambo/branches/4.6/includes/compat.php42x.php
Parent Directory
|
Revision Log
Revision 1 -
(view)
(download)
Original Path: mambo/trunk/includes/compat.php42x.php
| 1 : | root | 1 | <?php |
| 2 : | /** ensure this file is being included by a parent file */ | ||
| 3 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 4 : | |||
| 5 : | /** | ||
| 6 : | * Replace file_get_contents() | ||
| 7 : | * | ||
| 8 : | * @category PHP | ||
| 9 : | * @package PHP_Compat | ||
| 10 : | * @link http://php.net/function.file_get_contents | ||
| 11 : | * @author Aidan Lister <aidan@php.net> | ||
| 12 : | * @version $Revision: 1.1 $ | ||
| 13 : | * @internal resource_context is not supported | ||
| 14 : | * @since PHP 5 | ||
| 15 : | * @require PHP 4.0.1 (trigger_error) | ||
| 16 : | */ | ||
| 17 : | if (!function_exists('file_get_contents')) { | ||
| 18 : | function file_get_contents($filename, $incpath = false, $resource_context = null) | ||
| 19 : | { | ||
| 20 : | if (false === $fh = fopen($filename, 'rb', $incpath)) { | ||
| 21 : | trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING); | ||
| 22 : | return false; | ||
| 23 : | } | ||
| 24 : | |||
| 25 : | clearstatcache(); | ||
| 26 : | if ($fsize = @filesize($filename)) { | ||
| 27 : | $data = fread($fh, $fsize); | ||
| 28 : | } else { | ||
| 29 : | $data = ''; | ||
| 30 : | while (!feof($fh)) { | ||
| 31 : | $data .= fread($fh, 8192); | ||
| 32 : | } | ||
| 33 : | } | ||
| 34 : | |||
| 35 : | fclose($fh); | ||
| 36 : | return $data; | ||
| 37 : | } | ||
| 38 : | } | ||
| 39 : | if (!defined('FILE_USE_INCLUDE_PATH')) { | ||
| 40 : | define('FILE_USE_INCLUDE_PATH', 1); | ||
| 41 : | } | ||
| 42 : | |||
| 43 : | if (!defined('FILE_APPEND')) { | ||
| 44 : | define('FILE_APPEND', 8); | ||
| 45 : | } | ||
| 46 : | |||
| 47 : | |||
| 48 : | /** | ||
| 49 : | * Replace file_put_contents() | ||
| 50 : | * | ||
| 51 : | * @category PHP | ||
| 52 : | * @package PHP_Compat | ||
| 53 : | * @link http://php.net/function.file_put_contents | ||
| 54 : | * @author Aidan Lister <aidan@php.net> | ||
| 55 : | * @version $Revision: 1.1 $ | ||
| 56 : | * @internal resource_context is not supported | ||
| 57 : | * @since PHP 5 | ||
| 58 : | * @require PHP 4.0.1 (trigger_error) | ||
| 59 : | */ | ||
| 60 : | if (!function_exists('file_put_contents')) { | ||
| 61 : | function file_put_contents($filename, $content, $flags = null, $resource_context = null) | ||
| 62 : | { | ||
| 63 : | // If $content is an array, convert it to a string | ||
| 64 : | if (is_array($content)) { | ||
| 65 : | $content = implode('', $content); | ||
| 66 : | } | ||
| 67 : | |||
| 68 : | // If we don't have a string, throw an error | ||
| 69 : | if (!is_scalar($content)) { | ||
| 70 : | trigger_error('file_put_contents() The 2nd parameter should be either a string or an array', E_USER_WARNING); | ||
| 71 : | return false; | ||
| 72 : | } | ||
| 73 : | |||
| 74 : | // Get the length of date to write | ||
| 75 : | $length = strlen($content); | ||
| 76 : | |||
| 77 : | // Check what mode we are using | ||
| 78 : | $mode = ($flags & FILE_APPEND) ? | ||
| 79 : | $mode = 'a' : | ||
| 80 : | $mode = 'w'; | ||
| 81 : | |||
| 82 : | // Check if we're using the include path | ||
| 83 : | $use_inc_path = ($flags & FILE_USE_INCLUDE_PATH) ? | ||
| 84 : | true : | ||
| 85 : | false; | ||
| 86 : | |||
| 87 : | // Open the file for writing | ||
| 88 : | if (($fh = @fopen($filename, $mode, $use_inc_path)) === false) { | ||
| 89 : | trigger_error('file_put_contents() failed to open stream: Permission denied', E_USER_WARNING); | ||
| 90 : | return false; | ||
| 91 : | } | ||
| 92 : | |||
| 93 : | // Write to the file | ||
| 94 : | $bytes = 0; | ||
| 95 : | if (($bytes = @fwrite($fh, $content)) === false) { | ||
| 96 : | $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s', | ||
| 97 : | $length, | ||
| 98 : | $filename); | ||
| 99 : | trigger_error($errormsg, E_USER_WARNING); | ||
| 100 : | return false; | ||
| 101 : | } | ||
| 102 : | |||
| 103 : | // Close the handle | ||
| 104 : | @fclose($fh); | ||
| 105 : | |||
| 106 : | // Check all the data was written | ||
| 107 : | if ($bytes != $length) { | ||
| 108 : | $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.', | ||
| 109 : | $bytes, | ||
| 110 : | $length); | ||
| 111 : | trigger_error($errormsg, E_USER_WARNING); | ||
| 112 : | return false; | ||
| 113 : | } | ||
| 114 : | |||
| 115 : | // Return length | ||
| 116 : | return $bytes; | ||
| 117 : | } | ||
| 118 : | } | ||
| 119 : | |||
| 120 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

