From 7a4d6b3ac3575caedf9429940f54688411cbf5e9 Mon Sep 17 00:00:00 2001
From: Jan-E <github@ehrhardt.nl>
Date: Sun, 19 Apr 2015 18:49:48 +0200
Subject: [PATCH 1/2] PHP7 compatibility

---
 uploadprogress.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/uploadprogress.c b/uploadprogress.c
index 30f6758..7a52ba7 100644
--- a/uploadprogress.c
+++ b/uploadprogress.c
@@ -71,7 +71,7 @@ PHPAPI extern int (*php_rfc1867_callback)(unsigned int , void *, void ** TSRMLS_
  */
 static int uploadprogress_php_rfc1867_file(unsigned int event, void  *event_data, void **data TSRMLS_DC)
 {
-    zval handler;
+    //zval handler;
     char *callable = NULL;
     uploadprogress_data * progress;
     int read_bytes;
@@ -157,7 +157,11 @@ static int uploadprogress_php_rfc1867_file(unsigned int event, void  *event_data
 
             if (get_contents) {
                 php_stream *stream;
+#if defined(ZEND_ENGINE_3)
+                int options = 0;
+#else
                 int options = ENFORCE_SAFE_MODE;
+#endif
 
                 stream = php_stream_open_wrapper(progress->data_filename, "ab", options, NULL);
                 if (stream) {
@@ -301,7 +305,7 @@ PHP_FUNCTION(uploadprogress_get_info)
 {
     char * id;
     int id_lg;
-    char method;
+    //char method;
 
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &id, &id_lg) == FAILURE) {
         return;
@@ -417,7 +421,11 @@ static void uploadprogress_file_php_get_info(char * id, zval * return_value)
                         v[index] = 0;
                     }
                 }
+#if defined(ZEND_ENGINE_3)
+                add_assoc_string( return_value, k, v );
+#else
                 add_assoc_string( return_value, k, v, 1 );
+#endif
             }
             fclose(F);
         }
@@ -432,10 +440,22 @@ static void uploadprogress_file_php_get_info(char * id, zval * return_value)
  */
 static void uploadprogress_file_php_get_contents(char *id, char *fieldname, long maxlen, zval *return_value)
 {
+#if defined(ZEND_ENGINE_3)
+    char *filename, *template, *data_identifier;
+    zend_string *contents;
+#else
     char *filename, *template, *contents, *data_identifier;
+#endif
     php_stream *stream;
+#if defined(ZEND_ENGINE_3)
+    int options = 0;
+#else
     int options = ENFORCE_SAFE_MODE;
-    int len, newlen;
+#endif
+    int len;
+#if PHP_API_VERSION < 20100412
+    int newlen;
+#endif
     TSRMLS_FETCH();
 
     template = INI_STR("uploadprogress.file.contents_template");
@@ -455,7 +475,13 @@ static void uploadprogress_file_php_get_contents(char *id, char *fieldname, long
         }
 
         /* uses mmap if possible */
+#if defined(ZEND_ENGINE_3)
+        contents = php_stream_copy_to_mem(stream, maxlen, 0);
+        len = contents->len;
+        if (contents && len > 0) {
+#else
         if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) {
+#endif
 
 #if PHP_API_VERSION < 20100412
             if (PG(magic_quotes_runtime)) {
@@ -463,7 +489,11 @@ static void uploadprogress_file_php_get_contents(char *id, char *fieldname, long
                 len = newlen;
             }
 #endif
+#if defined(ZEND_ENGINE_3)
+            RETVAL_STR(contents);
+#else
             RETVAL_STRINGL(contents, len, 0);
+#endif
         } else if (len == 0) {
             RETVAL_EMPTY_STRING();
         } else {
-- 
2.1.4


From 95d8a0fd4554e10c215d3ab301e901bd8f99c5d9 Mon Sep 17 00:00:00 2001
From: Jan-E <github@ehrhardt.nl>
Date: Mon, 20 Apr 2015 22:20:40 +0200
Subject: [PATCH 2/2] int id_lg should be size_t id_lg

---
 uploadprogress.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/uploadprogress.c b/uploadprogress.c
index 7a52ba7..3d73d15 100644
--- a/uploadprogress.c
+++ b/uploadprogress.c
@@ -304,7 +304,11 @@ PHP_MINFO_FUNCTION(uploadprogress)
 PHP_FUNCTION(uploadprogress_get_info)
 {
     char * id;
+#if defined(ZEND_ENGINE_3)
+    size_t id_lg;
+#else
     int id_lg;
+#endif
     //char method;
 
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &id, &id_lg) == FAILURE) {
-- 
2.1.4

--- a/uploadprogress.c	2011-08-15 09:21:10.000000000 -0400
+++ b/uploadprogress.c	2016-12-07 11:05:47.961377088 -0500
@@ -213,7 +213,7 @@
             FILE *F;
             F = VCWD_FOPEN(progress->identifier_tmp, "wb");
             if (F) {
-                fprintf(F, "upload_id=%s\nfieldname=%s\nfilename=%s\ntime_start=%d\ntime_last=%d\nspeed_average=%d\nspeed_last=%d\nbytes_uploaded=%d\nbytes_total=%d\nfiles_uploaded=%d\nest_sec=%d\n",
+                fprintf(F, "upload_id=%s\nfieldname=%s\nfilename=%s\ntime_start=%ld\ntime_last=%ld\nspeed_average=%d\nspeed_last=%d\nbytes_uploaded=%ld\nbytes_total=%ld\nfiles_uploaded=%d\nest_sec=%d\n",
                 progress->upload_id, progress->fieldname, progress->filename,
                 progress->time_start, progress->time_last,
                 progress->speed_average, progress->speed_last,
