summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/standard/basic_functions.c1
-rw-r--r--ext/standard/file.c45
-rwxr-xr-xmain/streams.c2
3 files changed, 46 insertions, 2 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 5f50c1c07e..240eb3b73e 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -611,6 +611,7 @@ function_entry basic_functions[] = {
PHP_FE(tempnam, NULL)
PHP_STATIC_FE("tmpfile", php_if_tmpfile, NULL)
PHP_FE(file, NULL)
+ PHP_FE(get_file_contents, NULL)
PHP_FE(fgetcsv, NULL)
PHP_FE(flock, NULL)
PHP_FE(get_meta_tags, NULL)
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 5734db3a1f..06bcb9daf1 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -365,6 +365,49 @@ PHP_FUNCTION(get_meta_tags)
}
/* }}} */
+
+/* {{{ proto string get_file_contents(string filename [, bool use_include_path])
+ Read the entire file into a string */
+PHP_FUNCTION(get_file_contents)
+{
+ char *filename;
+ int filename_len;
+ char *contents, *target_buf;
+ zend_bool use_include_path = 0;
+ php_stream *stream;
+ int len, newlen;
+
+ /* Parse arguments */
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b",
+ &filename, &filename_len, &use_include_path) == FAILURE) {
+ return;
+ }
+
+ stream = php_stream_open_wrapper(filename, "rb",
+ use_include_path | ENFORCE_SAFE_MODE | REPORT_ERRORS,
+ NULL TSRMLS_CC);
+ if (!stream) {
+ RETURN_FALSE;
+ }
+
+ /* uses mmap if possible */
+ if ((len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0)) > 0) {
+
+ if (PG(magic_quotes_runtime)) {
+ contents = php_addslashes(contents, len, &newlen, 1 TSRMLS_CC); /* 1 = free source string */
+ len = newlen;
+ }
+
+ RETVAL_STRINGL(contents, len);
+ } else {
+ RETVAL_FALSE;
+ }
+
+ php_stream_close(stream);
+
+}
+/* }}} */
+
/* {{{ proto array file(string filename [, bool use_include_path])
Read entire file into an array */
@@ -390,7 +433,7 @@ PHP_FUNCTION(file)
stream = php_stream_open_wrapper(filename, "rb",
use_include_path | ENFORCE_SAFE_MODE | REPORT_ERRORS,
NULL TSRMLS_CC);
- if (!stream) {
+ if (!stream) {
RETURN_FALSE;
}
diff --git a/main/streams.c b/main/streams.c
index be5ae0812c..df562bfc7d 100755
--- a/main/streams.c
+++ b/main/streams.c
@@ -90,7 +90,7 @@ PHPAPI int php_stream_free(php_stream *stream, int call_dtor) /* {{{ */
ret = stream->ops->close(stream, call_dtor);
stream->abstract = NULL;
- if (call_dtor) {
+ if (call_dtor) {
/* tidy up any FILE* that might have been fdopened */
if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FDOPEN && stream->stdiocast) {
fclose(stream->stdiocast);