PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2004, PHP 5.1.0
-- Added optional offset parameter to stream_get_contents(). (Ilia)
+- Added optional offset parameter to stream_get_contents() and
+ file_get_contents(). (Ilia)
- Improved performance of:
. general execution/compilation. (Andi, Thies, Sterling, Dmitry, Marcus)
. switch statement. (Dmitry)
/* }}} */
-/* {{{ proto string file_get_contents(string filename [, bool use_include_path [, resource context]])
+/* {{{ proto string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset]]])
Read the entire file into a string */
PHP_FUNCTION(file_get_contents)
{
zend_bool use_include_path = 0;
php_stream *stream;
int len, newlen;
+ long offset = -1;
zval *zcontext = NULL;
php_stream_context *context = NULL;
/* Parse arguments */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|br!",
- &filename, &filename_len, &use_include_path, &zcontext) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|br!l",
+ &filename, &filename_len, &use_include_path, &zcontext, &offset) == FAILURE) {
return;
}
RETURN_FALSE;
}
+ if (offset > 0 && php_stream_seek(stream, offset, SEEK_SET) < 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to %ld position in the stream.", offset);
+ RETURN_FALSE;
+ }
+
/* uses mmap if possible */
if ((len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0)) > 0) {