Browse Source

Added optional maxlen parameter to file_get_contents().

PHP-5.1
Ilia Alshanetsky 21 years ago
parent
commit
55fd7ac601
  1. 1
      NEWS
  2. 9
      ext/standard/file.c

1
NEWS

@ -31,6 +31,7 @@ PHP NEWS
- Added sqlite_fetch_column_types() 3rd argument for arrays. (Ilia)
- Added optional offset parameter to stream_get_contents() and
file_get_contents(). (Ilia)
- Added optional maxlen parameter to file_get_contents(). (Ilia)
- Added SAPI hook to get the current request time. (Rasmus)
- Added new functions:
. array_diff_key() (Andrey)

9
ext/standard/file.c

@ -506,7 +506,7 @@ PHP_FUNCTION(get_meta_tags)
/* }}} */
/* {{{ proto string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset]]])
/* {{{ proto string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
Read the entire file into a string */
PHP_FUNCTION(file_get_contents)
{
@ -517,12 +517,13 @@ PHP_FUNCTION(file_get_contents)
php_stream *stream;
int len, newlen;
long offset = -1;
long maxlen = PHP_STREAM_COPY_ALL;
zval *zcontext = NULL;
php_stream_context *context = NULL;
/* Parse arguments */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|br!l",
&filename, &filename_len, &use_include_path, &zcontext, &offset) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|br!ll",
&filename, &filename_len, &use_include_path, &zcontext, &offset, &maxlen) == FAILURE) {
return;
}
@ -541,7 +542,7 @@ PHP_FUNCTION(file_get_contents)
}
/* uses mmap if possible */
if ((len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0)) > 0) {
if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) {
if (PG(magic_quotes_runtime)) {
contents = php_addslashes(contents, len, &newlen, 1 TSRMLS_CC); /* 1 = free source string */

Loading…
Cancel
Save