[-]
[+]
|
Changed |
php5-uploadprogress.spec
|
|
[-]
[+]
|
Deleted |
uploadprogress-0.3.0.tgz/uploadprogress-0.3.0/EXPERIMENTAL
^
|
@@ -1,5 +0,0 @@
-this extension is experimental,
-its functions may change their names
-or move to extension all together
-so do not rely to much on them
-you have been warned!
|
[-]
[+]
|
Deleted |
uploadprogress-0.3.0.tgz/uploadprogress-0.3.0/php_uploadprogress.h
^
|
@@ -1,91 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | unknown license: |
- +----------------------------------------------------------------------+
- +----------------------------------------------------------------------+
-*/
-
-/* $ Id: $ */
-
-#ifndef PHP_UPLOADPROGRESS_H
-#define PHP_UPLOADPROGRESS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <php.h>
-
-#ifdef HAVE_UPLOADPROGRESS
-
-#include <php_ini.h>
-#include <SAPI.h>
-#include <ext/standard/info.h>
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern zend_module_entry uploadprogress_module_entry;
-#define phpext_uploadprogress_ptr &uploadprogress_module_entry
-
-#ifdef PHP_WIN32
-#define PHP_UPLOADPROGRESS_API __declspec(dllexport)
-#else
-#define PHP_UPLOADPROGRESS_API
-#endif
-
-typedef struct _uploadprogress_data {
- char * identifier; /* full filename, or just the identifier, depending on method */
- char * identifier_tmp; /* full filename, or just the identifier, depending on method */
- time_t time_start;
- time_t time_last;
- unsigned int speed_average;
- unsigned int speed_last;
- unsigned long bytes_uploaded;
- unsigned long bytes_total;
- unsigned int files_uploaded;
- int est_sec;
-} uploadprogress_data;
-
-
-static char * uploadprogress_mk_filename(char * identifier, char * template);
-
-static void uploadprogress_file_php_get_info(char *, zval * );
-
-PHP_MINIT_FUNCTION(uploadprogress);
-PHP_MSHUTDOWN_FUNCTION(uploadprogress);
-PHP_RINIT_FUNCTION(uploadprogress);
-PHP_RSHUTDOWN_FUNCTION(uploadprogress);
-PHP_MINFO_FUNCTION(uploadprogress);
-
-#ifdef ZTS
-#include "TSRM.h"
-#endif
-
-
-PHP_FUNCTION(uploadprogress_get_info);
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif /* PHP_HAVE_UPLOADPROGRESS */
-
-#endif /* PHP_UPLOADPROGRESS_H */
-
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: noet sw=4 ts=4 fdm=marker
- * vim<600: noet sw=4 ts=4
- */
|
[-]
[+]
|
Deleted |
uploadprogress-0.3.0.tgz/uploadprogress-0.3.0/uploadprogress.c
^
|
@@ -1,362 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2003 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Christian Stocker (chregu@bitflux.ch) |
- | Derived from: Doru Petrescu (pdoru-php-upm@kappa.ro) |
- | http://pdoru.from.ro/upload-progress-meter/ |
- +----------------------------------------------------------------------+
-
- $Id: uploadprogress.c,v 1.1 2006/12/05 12:00:12 chregu Exp $
-*/
-/* $ Id: $ */
-
-#include "php_uploadprogress.h"
-#include "rfc1867.h"
-
-
-#if HAVE_UPLOADPROGRESS
-
-/* {{{ uploadprogress_functions[] */
-function_entry uploadprogress_functions[] = {
- PHP_FE(uploadprogress_get_info, NULL)
- { NULL, NULL, NULL }
-};
-/* }}} */
-
-PHP_INI_BEGIN()
-PHP_INI_ENTRY("uploadprogress.file.filename_template", "/tmp/upt_%s.txt", PHP_INI_ALL, NULL)
-PHP_INI_END()
-
-
-
-/* {{{ uploadprogress_module_entry
-*/
-zend_module_entry uploadprogress_module_entry = {
- STANDARD_MODULE_HEADER,
- "uploadprogress",
- uploadprogress_functions,
- PHP_MINIT(uploadprogress), /* Replace with NULL if there is nothing to do at php startup */
- PHP_MSHUTDOWN(uploadprogress), /* Replace with NULL if there is nothing to do at php shutdown */
- PHP_RINIT(uploadprogress), /* Replace with NULL if there is nothing to do at request start */
- PHP_RSHUTDOWN(uploadprogress), /* Replace with NULL if there is nothing to do at request end */
- PHP_MINFO(uploadprogress),
- "0.0.1",
- STANDARD_MODULE_PROPERTIES
-};
-/* }}} */
-
-#ifdef COMPILE_DL_UPLOADPROGRESS
-ZEND_GET_MODULE(uploadprogress)
-#endif
-
-
-extern int (*php_rfc1867_callback)(unsigned int , void *, void ** TSRMLS_DC);
-
-static int uploadprogress_php_rfc1867_file(unsigned int event, void *event_data, void **data TSRMLS_DC)
-{
- zval handler;
- char *callable = NULL;
- uploadprogress_data * progress;
- int read_bytes;
-
- progress = *data;
- if (event == MULTIPART_EVENT_START) {
- multipart_event_start *e_data;
- e_data = (multipart_event_start*) event_data;
- progress = emalloc( sizeof(uploadprogress_data) );
- progress->bytes_total = e_data->content_length;
- progress->identifier = NULL;
- progress->identifier_tmp = NULL;
- progress->time_start = time(NULL);
- *data = progress;
- } else if (event == MULTIPART_EVENT_FORMDATA) {
-
- multipart_event_formdata *e_data;
- e_data = (multipart_event_formdata*) event_data;
- read_bytes = e_data->post_bytes_processed;
- if (e_data->newlength) {
- *e_data->newlength = e_data->length;
- }
-
- if (strcmp(e_data->name, "UPLOAD_IDENTIFIER") == 0) {
-
- char * template = INI_STR("uploadprogress.file.filename_template");
- if (strcmp(template, "") == 0) {
- return 0;
- }
-
- progress->time_last = time(NULL);
- progress->speed_average = 0;
- progress->speed_last = 0;
- progress->bytes_uploaded = read_bytes;
- progress->files_uploaded = 0;
- progress->est_sec = 0;
- progress->identifier = uploadprogress_mk_filename(*e_data->value, template);
- progress->identifier_tmp = emalloc(strlen( progress->identifier) + 4);
- sprintf( progress->identifier_tmp, "%s.wr", progress->identifier );
- }
- }
-
- if (progress->identifier) {
-
- if (event == MULTIPART_EVENT_FILE_START) {
- multipart_event_file_start *e_data;
-
- e_data = (multipart_event_file_start*) event_data;
- read_bytes = e_data->post_bytes_processed;
-
- } else if (event == MULTIPART_EVENT_FILE_DATA) {
- multipart_event_file_data *e_data;
-
- e_data = (multipart_event_file_data*) event_data;
- read_bytes = e_data->post_bytes_processed;
-
-
- } else if (event == MULTIPART_EVENT_FILE_END) {
- multipart_event_file_end *e_data;
-
- e_data = (multipart_event_file_end*) event_data;
-
- read_bytes = e_data->post_bytes_processed;
- progress->files_uploaded++;
- } else if ( event == MULTIPART_EVENT_END ) {
- VCWD_UNLINK( progress->identifier );
- efree( progress->identifier );
- efree( progress->identifier_tmp );
- efree( progress );
-
- return 0;
-
- }
-
- time_t crtime = time(NULL);
- int d,dt,ds;
-
- if (progress->time_last > crtime) { /* just in case we encounter a fracture in time */
- progress->time_start = progress->time_last = crtime;
- }
-
- dt = crtime - progress->time_last;
- ds = crtime - progress->time_start;
- d = read_bytes - progress->bytes_uploaded;
-
-
- if (dt) {
- progress->speed_last = d/dt;
-
- progress->time_last = crtime;
- progress->bytes_uploaded = read_bytes;
-
- progress->speed_average = ds ? read_bytes / ds : 0;
- progress->est_sec = progress->speed_average ? (progress->bytes_total - read_bytes) / progress->speed_average : -1;
- }
- if (dt || event >= MULTIPART_EVENT_FILE_END) {
-
-
- FILE *F;
- F = VCWD_FOPEN(progress->identifier_tmp, "wb");
- if (F) {
- fprintf(F, "time_start=%d\ntime_last=%d\nspeed_average=%d\nspeed_last=%d\nbytes_uploaded=%d\nbytes_total=%d\nfiles_uploaded=%d\nest_sec=%d\n",
- progress->time_start, progress->time_last,
- progress->speed_average, progress->speed_last,
- progress->bytes_uploaded, progress->bytes_total,
- progress->files_uploaded,
- progress->est_sec );
- fclose(F);
- VCWD_RENAME(progress->identifier_tmp,progress->identifier);
- }
- }
-
-
- }
- if (event == MULTIPART_EVENT_END ) {
- if (progress->identifier) {
- efree( progress->identifier );
- }
- if (progress->identifier_tmp) {
- efree( progress->identifier_tmp );
- }
- efree( progress );
-
- }
-}
-
-
-/* {{{ PHP_MINIT_FUNCTION */
-PHP_MINIT_FUNCTION(uploadprogress)
-{
- REGISTER_INI_ENTRIES();
- php_rfc1867_callback = uploadprogress_php_rfc1867_file;
-
- /* add your stuff here */
-
- return SUCCESS;
-}
-/* }}} */
-
-
-/* {{{ PHP_MSHUTDOWN_FUNCTION */
-PHP_MSHUTDOWN_FUNCTION(uploadprogress)
-{
-
- UNREGISTER_INI_ENTRIES();
- php_rfc1867_callback = NULL;
-
- /* add your stuff here */
-
-
- return SUCCESS;
-}
-/* }}} */
-
-
-
-/* {{{ PHP_RINIT_FUNCTION */
-PHP_RINIT_FUNCTION(uploadprogress)
-{
- /* add your stuff here */
-
-
- return SUCCESS;
-}
-/* }}} */
-
-
-/* {{{ PHP_RSHUTDOWN_FUNCTION */
-PHP_RSHUTDOWN_FUNCTION(uploadprogress)
-{
- /* add your stuff here */
-
- return SUCCESS;
-}
-/* }}} */
-
-
-/* {{{ PHP_MINFO_FUNCTION */
-PHP_MINFO_FUNCTION(uploadprogress)
-{
- char buffer[ 512 ] ;
- php_info_print_table_start() ;
-
- php_info_print_table_header( 2, "uploadprogress support", "enabled" ) ;
- snprintf( buffer, 512, "0.3.0-beta");
-
- php_info_print_table_row( 2, "Version", buffer ) ;
-
- php_info_print_box_end();
- /* add your stuff here */
-
-}
-
-
-/* }}} */
-
-
-
-
-/* {{{ proto bool uploadprogress_register(callback callback)
-*/
-
-PHP_FUNCTION(uploadprogress_get_info)
-{
- char * id;
- int id_lg;
- char method;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &id, &id_lg) == FAILURE) {
- return;
- }
-
- return uploadprogress_file_php_get_info( id, return_value );
-
- RETURN_FALSE;
-}
-
-static char * uploadprogress_mk_filename(char * identifier, char * template)
-{
- char * x;
- char * filename;
-
- filename = emalloc( strlen(template) + strlen(identifier) + 3 );
-
- x = strstr( template, "%s" );
- if (x==NULL) {
- sprintf( filename, "%s/%s", template, identifier );
- }else{
- strcpy( filename, template );
- strcpy( filename + (x - template), identifier );
- strcat( filename, x+2 );
- }
- return filename;
-}
-
-static void uploadprogress_file_php_get_info(char * id, zval * return_value)
-{
- char s[1024];
- char * filename;
- FILE *F;
- TSRMLS_FETCH();
-
- char * template = INI_STR("uploadprogress.file.filename_template");
-
-
- if (strcmp(template, "") == 0) {
- return;
- } else {
- filename = uploadprogress_mk_filename( id, template );
- if (!filename) return;
-
- F = VCWD_FOPEN(filename, "rb");
-
- if (F) {
- array_init(return_value);
-
- while ( fgets(s, 1000, F) ) {
- char *k, *v, *e;
- e = strchr(s,'=');
- if (!e) continue;
-
- *e = 0; /* break the line into 2 parts */
- v = e+1;
- k = s;
-
- /* trim spaces in front and after the name/value */
- while (*k && *k <= 32) v++;
- while (*v && *v <= 32) v++;
- for (e=k; *e; e++) if (*e <= 32) { *e = 0; break; }
- for (e=v; *e; e++) if (*e <= 32) { *e = 0; break; }
-
- add_assoc_string( return_value, k, v, 1 );
- }
- fclose(F);
- }
-
- if (filename) efree(filename);
- return;
- }
-}
-
-
-
-#endif /* HAVE_UPLOADPROGRESS */
-
-
-/*
-* Local variables:
-* tab-width: 4
-* c-basic-offset: 4
-* End:
-* vim600: noet sw=4 ts=4 fdm=marker
-* vim<600: noet sw=4 ts=4
-*/
|
|
Deleted |
uploadprogress-0.9.0.tgz
^
|
|
Deleted |
uploadprogress-0.9.1.tgz
^
|
|
Deleted |
uploadprogress-0.9.2.tgz
^
|
|
Deleted |
uploadprogress-1.0.0.tgz
^
|
|
Deleted |
uploadprogress-1.0.1.tgz
^
|
[-]
[+]
|
Changed |
uploadprogress-1.0.2.tgz/package.xml
^
|
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0">
-<package version="1.0" packagerversion="1.4.11">
+<package version="1.0" packagerversion="1.9.4">
<name>uploadprogress</name>
<summary>An extension to track progress of a file upload.</summary>
- <description>PHP 5.2 is needed
+ <description>See http://svn.php.net/viewvc/pecl/uploadprogress/trunk/examples/ for a little example.
+ It is only known to work on Apache with mod_php, other SAPI implementations unfortunately still have issues.
+ At least PHP 5.2 is needed.
</description>
<maintainers>
<maintainer>
@@ -12,20 +14,29 @@
<email>chregu@php.net</email>
<role>lead</role>
</maintainer>
+ <maintainer>
+ <user>ramsey</user>
+ <name>Ben Ramsey</name>
+ <email>ramsey@php.net</email>
+ <role>developer</role>
+ </maintainer>
</maintainers>
<release>
- <version>0.3.0</version>
- <date>2006-12-05</date>
+ <version>1.0.2</version>
+ <date>2011-07-26</date>
<license>PHP License</license>
- <state>beta</state>
- <notes>Initial release
+ <state>stable</state>
+ <notes>- Make it work with PHP 5.4
</notes>
<deps>
<dep type="php" rel="ge" version="5.2.0"/>
</deps>
<filelist>
+ <file role="doc" name="examples/index.php"/>
+ <file role="doc" name="examples/info.php"/>
+ <file role="doc" name="examples/server.php"/>
<file role="src" name="config.m4"/>
- <file role="doc" name="EXPERIMENTAL"/>
+ <file role="src" name="config.w32"/>
<file role="src" name="php_uploadprogress.h"/>
<file role="src" name="uploadprogress.c"/>
</filelist>
|
[-]
[+]
|
Changed |
uploadprogress-1.0.2.tgz/package2.xml
^
|
@@ -1,33 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.4.11" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+<package packagerversion="1.9.4" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>uploadprogress</name>
<channel>pecl.php.net</channel>
<summary>An extension to track progress of a file upload.</summary>
- <description>PHP 5.2 is needed</description>
+ <description>See http://svn.php.net/viewvc/pecl/uploadprogress/trunk/examples/ for a little example.
+ It is only known to work on Apache with mod_php, other SAPI implementations unfortunately still have issues.
+ At least PHP 5.2 is needed.</description>
<lead>
<name>Christian Stocker</name>
<user>chregu</user>
<email>chregu@php.net</email>
<active>yes</active>
</lead>
- <date>2006-12-05</date>
- <time>13:01:18</time>
+ <developer>
+ <name>Ben Ramsey</name>
+ <user>ramsey</user>
+ <email>ramsey@php.net</email>
+ <active>yes</active>
+ </developer>
+ <date>2011-07-26</date>
+ <time>09:47:04</time>
<version>
- <release>0.3.0</release>
- <api>0.3.0</api>
+ <release>1.0.2</release>
+ <api>1.0.0</api>
</version>
<stability>
- <release>beta</release>
- <api>beta</api>
+ <release>stable</release>
+ <api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
- <notes>Initial release</notes>
+ <notes>
+- Make it work with PHP 5.4
+ </notes>
<contents>
<dir name="/">
+ <file md5sum="f2f46c18444a8ea0ca7fece8defb7bbf" name="examples/index.php" role="doc" />
+ <file md5sum="dd7f9f607dc24d9fd1ad0fa7e750fedf" name="examples/server.php" role="doc" />
+ <file md5sum="4c0cc40ceead2068e97feb424745a84e" name="examples/info.php" role="doc" />
<file md5sum="741572e73cf5856c2481954588f02283" name="config.m4" role="src" />
- <file md5sum="7291f1b05a4608bc9223993fd2bea6c2" name="EXPERIMENTAL" role="doc" />
- <file md5sum="1f31f773c2e7cfe215be5aee10df76fa" name="php_uploadprogress.h" role="src" />
- <file md5sum="f01a56d3db8b7df06ffc9ffbf3573241" name="uploadprogress.c" role="src" />
+ <file md5sum="10b28617f1b1003b80c27beb654d16f8" name="config.w32" role="src" />
+ <file md5sum="2c8c8e4f55868b70540130610ebede73" name="php_uploadprogress.h" role="src" />
+ <file md5sum="6ce285ba9aa7a463ab51acc0050867a6" name="uploadprogress.c" role="src" />
</dir>
</contents>
<dependencies>
|
[-]
[+]
|
Changed |
uploadprogress-1.0.2.tgz/uploadprogress-1.0.2/config.m4
^
|
(renamed from uploadprogress-0.3.0/config.m4)
|
[-]
[+]
|
Changed |
uploadprogress-1.0.2.tgz/uploadprogress-1.0.2/config.m4
^
|
(renamed from uploadprogress-0.3.0/config.m4)
|
[-]
[+]
|
Added |
uploadprogress-1.0.2.tgz/uploadprogress-1.0.2/config.w32
^
|
@@ -0,0 +1,9 @@
+// $Id: config.w32 224439 2006-12-05 23:10:49Z fmk $
+// vim:ft=javascript
+
+ARG_ENABLE('uploadprogress' , 'The Upload Progress extension', 'no');
+
+if (PHP_UPLOADPROGRESS != "no") {
+ EXTENSION("uploadprogress", "uploadprogress.c");
+ AC_DEFINE('HAVE_UPLOADPROGRESS', 1, 'The Upload Progress extension');
+}
|
[-]
[+]
|
Added |
uploadprogress-1.0.2.tgz/uploadprogress-1.0.2/examples/index.php
^
|
@@ -0,0 +1,204 @@
+<?php
+/*
+ +----------------------------------------------------------------------+
+ | Uploadprogress extension |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2006-2008 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Christian Stocker (chregu@php.net) |
+ +----------------------------------------------------------------------+
+*/
+
+ $id = md5(microtime() . rand());
+
+ function return_bytes($val) {
+ $val = trim($val);
+ $last = strtolower($val[strlen($val)-1]);
+ switch($last) {
+ // The 'G' modifier is available since PHP 5.1.0
+ case 'g':
+ $val *= 1024;
+ case 'm':
+ $val *= 1024;
+ case 'k':
+ $val *= 1024;
+ }
+
+ return $val;
+}
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org" />
+<script type="text/javascript">
+
+
+var UP = function() {
+
+ /* private variables */
+
+ var ifr = null;
+
+ var startTime = null;
+ var upload_max_filesize = <?php echo return_bytes(ini_get('upload_max_filesize'));?>;
+
+ var infoUpdated = 0;
+
+ var writeStatus = function(text,color) {
+ var statDiv = document.getElementById("status");
+ if (color == 1 ) {
+ statDiv.style.backgroundColor = "green";
+ } else if (color == 2 ) {
+ statDiv.style.backgroundColor = "orange";
+ } else if (color == 3 ) {
+ statDiv.style.backgroundColor = "red";
+ } else {
+ statDiv.style.backgroundColor = "white";
+ }
+ statDiv.innerHTML = text;
+ }
+
+
+ return {
+ start: function() {
+ ifr = document.getElementById("ifr");
+ startTime = new Date();
+ infoUpdated = 0;
+ this.requestInfo();
+ },
+ stop: function(files) {
+ if (typeof files == 'undefined' || files) {
+ var secs = (new Date() - startTime)/1000;
+ var statusText = "Upload succeeded, it took " + secs + " seconds. <br/> ";
+ if (infoUpdated > 0) {
+ writeStatus(statusText + "You had " + infoUpdated + " updates from the progress meter, looks like it's working fine",1);
+ } else {
+ statusText += "BUT there were no progress meter updates<br/> ";
+ if (secs < 3) {
+ writeStatus(statusText + "Your upload was maybe too short, try with a bigger file or a slower connection",2);
+ } else {
+ writeStatus(statusText + "Your upload should have taken long enough to have an progress update. Maybe it really does not work...",3);
+ }
+
+
+
+ }
+ } else {
+ writeStatus('PHP did not report any uploaded file, maybe it was too large, try a smaller one (post_max_size: <?php echo ini_get('post_max_size');?>)',3);
+ }
+ startTime = null;
+ },
+ requestInfo: function() {
+ ifr.src="info.php?ID=<?php echo $id;?>&"+new Date();
+ },
+
+ updateInfo: function(uploaded, total, estimatedSeconds) {
+ if (startTime) {
+ if (uploaded) {
+ infoUpdated++;
+ if (total > upload_max_filesize) {
+ writeStatus("The file is too large and won't be available for PHP after the upload<br/> Your file size is " + total + " bytes. Allowed is " + upload_max_filesize + " bytes. That's " + Math.round (total / upload_max_filesize * 100) + "% too large<br/> Download started since " + (new Date() - startTime)/1000 + " seconds. " + Math.floor(uploaded / total * 100) + "% done, " + estimatedSeconds + " seconds to go",2);
+ } else {
+ writeStatus("Download started since " + (new Date() - startTime)/1000 + " seconds. " + Math.floor(uploaded / total * 100) + "% done, " + estimatedSeconds + " seconds to go");
+ }
+ } else {
+ writeStatus("Download started since " + (new Date() - startTime)/1000 + " seconds. No progress info yet");
+ }
+ window.setTimeout("UP.requestInfo()",1000);
+ }
+ }
+
+
+ }
+
+}()
+
+
+</script>
+<title> php5.2 uploadprogress Meter - Simple Demo</title>
+
+</head>
+
+<body>
+ <form onsubmit="UP.start()" target="ifr2" action="server.php" enctype="multipart/form-data" method="post">
+ <input type="hidden" name="UPLOAD_IDENTIFIER" value="<?php echo $id;?>" />
+ <label>Select File:</label>
+ <input type="file" name="file" />
+ <br/>
+ <label>Select File:</label>
+ <input type="file" name="file2" />
+
+ <br/>
+
+ <label>Upload File:</label>
+ <input type="submit" value="Upload File" />
+ <br/>
+ ('upload_max_filesize' is <?php echo ini_get('upload_max_filesize');?> per file)<br/>
+
+ ('post_max_size' is <?php echo ini_get('post_max_size');?> per submit)<br/>
+
+ <?php
+
+
+ $templateini = ini_get("uploadprogress.file.filename_template");
+ $testid = "thisisjustatest";
+ $template = sprintf($templateini,$testid);
+ $templateerror = false;
+ if ($template && $template != $templateini && @touch ($template) && file_exists($template)) {
+ // print '('.$templateini.' is writable. The realpath is ' . str_replace($testid,"%s",realpath($template)) .')';
+ unlink($template);
+ } else {
+ $templateerror = true;
+ }
+
+ ?>
+ </form>
+ <div id="status" style="border: 1px black solid;<?php
+ if (function_exists("uploadprogress_get_info")) {
+ if ($templateerror) {
+ print 'background-color: red;"';
+ print ">Problem. ";
+ if ($template == $templateini) {
+ print "uploadprogress.file.filename_template ($templateini) doesn't have an %s in it for making unique temporary files. Please adjust.<br/>";
+ } else {
+ print "$templateini is NOT writable. <br/>Please make sure the directory exists and is writable for the webserver. <br/>
+ Or adjust the ini setting 'uploadprogress.file.filename_template' to a correct path.";
+ }
+ } else {
+ print 'background-color: green;">The uploadprogress extension is installed and initial checks show everything is good';
+ }
+
+
+ } else { ?>
+
+ background-color: red;">The uploadprogress extension is not installed.
+
+
+ <?php } ?>
+
+ </div>
+
+
+
+ <div>The info during the upload will be displayed here:</div>
+ <iframe id="ifr" src="info.php?ID=<?php echo $id;?>" width="500px" height="350px" name="ifr"></iframe>
+
+ <div>
+
+ The actual file upload happens here (and displays info, when it's finished):
+ </div>
+ <iframe name="ifr2" width="500px" height="300px" id="ifr2"></iframe>
+</body>
+
+</html>
|
[-]
[+]
|
Added |
uploadprogress-1.0.2.tgz/uploadprogress-1.0.2/examples/info.php
^
|
@@ -0,0 +1,54 @@
+<?php
+/*
+ +----------------------------------------------------------------------+
+ | Uploadprogress extension |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2006-2008 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Christian Stocker (chregu@php.net) |
+ +----------------------------------------------------------------------+
+*/
+
+if (function_exists("uploadprogress_get_info")) {
+
+ $info = uploadprogress_get_info($_GET['ID']);
+} else {
+ $info = false;
+}
+
+?>
+<html>
+<head>
+<script type="text/javascript">
+<?php
+
+
+if ($info !== null) {
+
+ print "parent.UP.updateInfo(".$info['bytes_uploaded'].",".$info['bytes_total'].",".$info['est_sec'].")";
+} else {
+ print "parent.UP.updateInfo()";
+}
+?>
+</script>
+
+</head>
+
+<body>
+<pre>
+<?php
+print "Date : " . date("c",time())."\n";
+print "ID : ". $_GET['ID'] ."\n";
+print 'var_dump($info): '. "\n";
+var_dump($info);
+?>
+</pre>
+</body>
|
[-]
[+]
|
Added |
uploadprogress-1.0.2.tgz/uploadprogress-1.0.2/examples/server.php
^
|
@@ -0,0 +1,49 @@
+<?php
+
+/*
+ +----------------------------------------------------------------------+
+ | Uploadprogress extension |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2006-2008 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Christian Stocker (chregu@php.net) |
+ +----------------------------------------------------------------------+
+*/
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org" />
+<script type="text/javascript">
+<?php
+if (count($_FILES) > 0) {
+ echo "parent.UP.stop(true);";
+} else {
+ echo "parent.UP.stop(false);";
+}
+?>
+</script>
+
+<title></title>
+</head>
+
+<body>
+ File uploaded:
+ <pre>
+<?php
+var_dump($_FILES);
+?>
+
+</pre>
+</body>
+</html>
|
[-]
[+]
|
Added |
uploadprogress-1.0.2.tgz/uploadprogress-1.0.2/php_uploadprogress.h
^
|
@@ -0,0 +1,113 @@
+/*
+ +----------------------------------------------------------------------+
+ | Uploadprogress extension |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2006-2008 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Christian Stocker (chregu@liip.ch) |
+ | Derived from: Doru Petrescu (pdoru-php-upm@kappa.ro) |
+ | http://pdoru.from.ro/upload-progress-meter/ |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id: php_uploadprogress.h 313707 2011-07-26 09:45:34Z chregu $ */
+
+#ifndef PHP_UPLOADPROGRESS_H
+#define PHP_UPLOADPROGRESS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <php.h>
+
+#ifdef HAVE_UPLOADPROGRESS
+
+#include <php_ini.h>
+#include <SAPI.h>
+#include <ext/standard/info.h>
+#include <ext/standard/php_string.h>
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern zend_module_entry uploadprogress_module_entry;
+#define phpext_uploadprogress_ptr &uploadprogress_module_entry
+
+#define PHP_UPLOADPROGRESS_VERSION "1.0.2"
+
+#ifdef PHP_WIN32
+#define PHP_UPLOADPROGRESS_API __declspec(dllexport)
+#else
+#define PHP_UPLOADPROGRESS_API
+#endif
+
+typedef struct _uploadprogress_data {
+ char * identifier; /* full filename, or just the identifier, depending on method */
+ char * identifier_tmp; /* full filename, or just the identifier, depending on method */
+ char * upload_id; /* raw string of the UPLOAD_IDENTIFIER */
+ char * data_filename; /* full filename of temporary data file */
+ char * fieldname; /* name of form field for current file being uploaded */
+ char * filename; /* filename of the uploaded file */
+ time_t time_start;
+ time_t time_last;
+ unsigned int speed_average;
+ unsigned int speed_last;
+ unsigned long bytes_uploaded;
+ unsigned long bytes_total;
+ unsigned int files_uploaded;
+ int est_sec;
+} uploadprogress_data;
+
+
+static char * uploadprogress_mk_filename(char * identifier, char * template);
+
+static void uploadprogress_file_php_get_info(char *, zval * );
+static void uploadprogress_file_php_get_contents(char *, char *, long, zval *);
+
+PHP_MINIT_FUNCTION(uploadprogress);
+PHP_MSHUTDOWN_FUNCTION(uploadprogress);
+PHP_RINIT_FUNCTION(uploadprogress);
+PHP_RSHUTDOWN_FUNCTION(uploadprogress);
+PHP_MINFO_FUNCTION(uploadprogress);
+
+#ifdef ZTS
+#include "TSRM.h"
+#endif
+
+
+PHP_FUNCTION(uploadprogress_get_info);
+PHP_FUNCTION(uploadprogress_get_contents);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif /* PHP_HAVE_UPLOADPROGRESS */
+
+#endif /* PHP_UPLOADPROGRESS_H */
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
|
[-]
[+]
|
Added |
uploadprogress-1.0.2.tgz/uploadprogress-1.0.2/uploadprogress.c
^
|
@@ -0,0 +1,490 @@
+/*
+ +----------------------------------------------------------------------+
+ | Uploadprogress extension |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2006-2008 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Christian Stocker (chregu@liip.ch) |
+ | Derived from: Doru Petrescu (pdoru-php-upm@kappa.ro) |
+ | http://pdoru.from.ro/upload-progress-meter/ |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id: uploadprogress.c 297236 2010-03-31 20:39:48Z johannes $ */
+
+#include "php_uploadprogress.h"
+#include "rfc1867.h"
+
+#if HAVE_UPLOADPROGRESS
+
+#ifdef P_tmpdir
+#define TMPDIR P_tmpdir
+#else
+#define TMPDIR "/tmp"
+#endif
+
+/* {{{ uploadprogress_functions[] */
+zend_function_entry uploadprogress_functions[] = {
+ PHP_FE(uploadprogress_get_info, NULL)
+ PHP_FE(uploadprogress_get_contents, NULL)
+ { NULL, NULL, NULL }
+};
+/* }}} */
+
+PHP_INI_BEGIN()
+PHP_INI_ENTRY("uploadprogress.file.filename_template", TMPDIR"/upt_%s.txt", PHP_INI_ALL, NULL)
+PHP_INI_ENTRY("uploadprogress.file.contents_template", TMPDIR"/upload_contents_%s", PHP_INI_ALL, NULL)
+PHP_INI_ENTRY("uploadprogress.get_contents", "0", PHP_INI_ALL, NULL)
+PHP_INI_END()
+
+/* {{{ uploadprogress_module_entry
+*/
+zend_module_entry uploadprogress_module_entry = {
+ STANDARD_MODULE_HEADER,
+ "uploadprogress",
+ uploadprogress_functions,
+ PHP_MINIT(uploadprogress), /* Replace with NULL if there is nothing to do at php startup */
+ PHP_MSHUTDOWN(uploadprogress), /* Replace with NULL if there is nothing to do at php shutdown */
+ PHP_RINIT(uploadprogress), /* Replace with NULL if there is nothing to do at request start */
+ PHP_RSHUTDOWN(uploadprogress), /* Replace with NULL if there is nothing to do at request end */
+ PHP_MINFO(uploadprogress),
+ PHP_UPLOADPROGRESS_VERSION,
+ STANDARD_MODULE_PROPERTIES
+};
+/* }}} */
+
+#ifdef COMPILE_DL_UPLOADPROGRESS
+ZEND_GET_MODULE(uploadprogress)
+#endif
+
+PHPAPI extern int (*php_rfc1867_callback)(unsigned int , void *, void ** TSRMLS_DC);
+
+/* {{{ uploadprogress_php_rfc1867_file
+ */
+static int uploadprogress_php_rfc1867_file(unsigned int event, void *event_data, void **data TSRMLS_DC)
+{
+ zval handler;
+ char *callable = NULL;
+ uploadprogress_data * progress;
+ int read_bytes;
+ zend_bool get_contents = INI_BOOL("uploadprogress.get_contents");
+
+ progress = *data;
+ if (event == MULTIPART_EVENT_START) {
+ multipart_event_start *e_data;
+ e_data = (multipart_event_start*) event_data;
+ progress = emalloc( sizeof(uploadprogress_data) );
+ progress->upload_id = NULL;
+ progress->fieldname = NULL;
+ progress->data_filename = NULL;
+ progress->bytes_total = e_data->content_length;
+ progress->identifier = NULL;
+ progress->identifier_tmp = NULL;
+ progress->time_start = time(NULL);
+ *data = progress;
+ } else if (event == MULTIPART_EVENT_FORMDATA) {
+
+ multipart_event_formdata *e_data;
+ e_data = (multipart_event_formdata*) event_data;
+ read_bytes = e_data->post_bytes_processed;
+ if (e_data->newlength) {
+ *e_data->newlength = e_data->length;
+ }
+
+ if (strcmp(e_data->name, "UPLOAD_IDENTIFIER") == 0) {
+
+ char * upload_id;
+ char * template = INI_STR("uploadprogress.file.filename_template");
+ if (strcmp(template, "") == 0) {
+ return 0;
+ }
+
+ upload_id = emalloc(strlen(*e_data->value) + 1);
+ strcpy(upload_id, *e_data->value);
+
+ progress->upload_id = upload_id;
+ progress->time_last = time(NULL);
+ progress->speed_average = 0;
+ progress->speed_last = 0;
+ progress->bytes_uploaded = read_bytes;
+ progress->files_uploaded = 0;
+ progress->est_sec = 0;
+ progress->identifier = uploadprogress_mk_filename(upload_id, template);
+ progress->identifier_tmp = emalloc(strlen( progress->identifier) + 4);
+ sprintf( progress->identifier_tmp, "%s.wr", progress->identifier );
+ }
+ }
+
+ if (progress->identifier) {
+ time_t crtime = time(NULL);
+ int d,dt,ds;
+
+ if (event == MULTIPART_EVENT_FILE_START) {
+ char * data_identifier;
+
+ multipart_event_file_start *e_data;
+
+ e_data = (multipart_event_file_start*) event_data;
+ read_bytes = e_data->post_bytes_processed;
+
+ progress->fieldname = e_data->name;
+ progress->filename = *e_data->filename;
+
+ data_identifier = emalloc(strlen(progress->upload_id) + strlen(progress->fieldname) + 2);
+ sprintf(data_identifier, "%s-%s", progress->upload_id, progress->fieldname);
+
+ if (get_contents) {
+ char * data_template = INI_STR("uploadprogress.file.contents_template");
+ if (strcmp(data_template, "") == 0) {
+ return 0;
+ }
+ progress->data_filename = uploadprogress_mk_filename(data_identifier, data_template);
+ }
+
+ } else if (event == MULTIPART_EVENT_FILE_DATA) {
+ multipart_event_file_data *e_data;
+
+ e_data = (multipart_event_file_data*) event_data;
+ read_bytes = e_data->post_bytes_processed;
+
+ if (get_contents) {
+ php_stream *stream;
+ int options = ENFORCE_SAFE_MODE;
+
+ stream = php_stream_open_wrapper(progress->data_filename, "ab", options, NULL);
+ if (stream) {
+ php_stream_write(stream, e_data->data, e_data->length);
+ }
+ php_stream_close(stream);
+ }
+
+ } else if (event == MULTIPART_EVENT_FILE_END) {
+ multipart_event_file_end *e_data;
+
+ e_data = (multipart_event_file_end*) event_data;
+
+ read_bytes = e_data->post_bytes_processed;
+ progress->files_uploaded++;
+
+ if (get_contents) {
+ VCWD_UNLINK(progress->data_filename);
+ efree(progress->data_filename);
+ }
+
+ } else if ( event == MULTIPART_EVENT_END ) {
+ VCWD_UNLINK( progress->identifier );
+ efree( progress->identifier );
+ efree( progress->identifier_tmp );
+ efree( progress );
+
+ return 0;
+
+ }
+
+ if (progress->time_last > crtime) { /* just in case we encounter a fracture in time */
+ progress->time_last = crtime;
+ }
+
+ dt = crtime - progress->time_last;
+ ds = crtime - progress->time_start;
+ d = read_bytes - progress->bytes_uploaded;
+
+
+ if (dt) {
+ progress->speed_last = d/dt;
+
+ progress->time_last = crtime;
+ progress->bytes_uploaded = read_bytes;
+
+ progress->speed_average = ds ? read_bytes / ds : 0;
+ progress->est_sec = progress->speed_average ? (progress->bytes_total - read_bytes) / progress->speed_average : -1;
+ }
+ if (dt || event >= MULTIPART_EVENT_FILE_END) {
+
+
+ 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",
+ progress->upload_id, progress->fieldname, progress->filename,
+ progress->time_start, progress->time_last,
+ progress->speed_average, progress->speed_last,
+ progress->bytes_uploaded, progress->bytes_total,
+ progress->files_uploaded,
+ progress->est_sec );
+ fclose(F);
+/* VCWD_RENAME on WIN32 and PHP < 5.3 has a bug, if target does exist */
+#ifdef PHP_WIN32
+#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3
+ VCWD_UNLINK(progress->identifier);
+#endif
+#endif
+ VCWD_RENAME(progress->identifier_tmp,progress->identifier);
+ }
+ }
+
+
+ }
+ if (event == MULTIPART_EVENT_END ) {
+ if (progress->identifier) {
+ efree( progress->identifier );
+ }
+ if (progress->identifier_tmp) {
+ efree( progress->identifier_tmp );
+ }
+ if (get_contents && progress->data_filename) {
+ efree(progress->data_filename);
+ }
+ efree( progress );
+
+ }
+}
+/* }}} */
+
+/* {{{ PHP_MINIT_FUNCTION */
+PHP_MINIT_FUNCTION(uploadprogress)
+{
+ REGISTER_INI_ENTRIES();
+ php_rfc1867_callback = uploadprogress_php_rfc1867_file;
+
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_MSHUTDOWN_FUNCTION */
+PHP_MSHUTDOWN_FUNCTION(uploadprogress)
+{
+
+ UNREGISTER_INI_ENTRIES();
+ php_rfc1867_callback = NULL;
+
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_RINIT_FUNCTION */
+PHP_RINIT_FUNCTION(uploadprogress)
+{
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_RSHUTDOWN_FUNCTION */
+PHP_RSHUTDOWN_FUNCTION(uploadprogress)
+{
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_MINFO_FUNCTION */
+PHP_MINFO_FUNCTION(uploadprogress)
+{
+ php_info_print_table_start();
+ php_info_print_table_header(2, "uploadprogress support", "enabled");
+ php_info_print_table_row(2, "Version", PHP_UPLOADPROGRESS_VERSION);
+ php_info_print_table_end();
+ DISPLAY_INI_ENTRIES();
+}
+/* }}} */
+
+/* {{{ proto array uploadprogress_get_info(string identifier)
+ */
+PHP_FUNCTION(uploadprogress_get_info)
+{
+ char * id;
+ int id_lg;
+ char method;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &id, &id_lg) == FAILURE) {
+ return;
+ }
+
+ uploadprogress_file_php_get_info( id, return_value );
+ return;
+
+}
+/* }}} */
+
+/* {{{ proto string uploadprogress_get_contents(string identifier, string fieldname[, int maxlen])
+ */
+PHP_FUNCTION(uploadprogress_get_contents)
+{
+ char *id, *fieldname;
+ int id_len, fieldname_len;
+ long maxlen = PHP_STREAM_COPY_ALL;
+ zend_bool get_contents = INI_BOOL("uploadprogress.get_contents");
+
+ if (!get_contents) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ "this function is disabled; set uploadprogress.get_contents = On to enable it");
+ RETURN_FALSE;
+ return;
+ }
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l",
+ &id, &id_len, &fieldname, &fieldname_len, &maxlen) == FAILURE) {
+ return;
+ }
+
+ if (ZEND_NUM_ARGS() == 3 && maxlen < 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "length must be greater than or equal to zero");
+ RETURN_FALSE;
+ }
+
+ uploadprogress_file_php_get_contents(id, fieldname, maxlen, return_value);
+ return;
+}
+/* }}} */
+
+/* {{{ uploadprogress_mk_filename
+ */
+static char * uploadprogress_mk_filename(char * identifier, char * template)
+{
+ char * x;
+ char * filename;
+
+ filename = emalloc( strlen(template) + strlen(identifier) + 3 );
+
+ x = strstr( template, "%s" );
+ if (x==NULL) {
+ sprintf( filename, "%s/%s", template, identifier );
+ }else{
+ strcpy( filename, template );
+ strcpy( filename + (x - template), identifier );
+ strcat( filename, x+2 );
+ }
+ return filename;
+}
+/* }}} */
+
+/* {{{ uploadprogress_file_php_get_info
+ */
+static void uploadprogress_file_php_get_info(char * id, zval * return_value)
+{
+ char s[1024];
+ char * filename;
+ char * template;
+ FILE *F;
+ TSRMLS_FETCH();
+
+ template = INI_STR("uploadprogress.file.filename_template");
+
+
+ if (strcmp(template, "") == 0) {
+ return;
+ } else {
+ filename = uploadprogress_mk_filename( id, template );
+ if (!filename) return;
+
+ F = VCWD_FOPEN(filename, "rb");
+
+ if (F) {
+ array_init(return_value);
+
+ while ( fgets(s, 1000, F) ) {
+ char *k, *v, *e;
+ int index = 0;
+ e = strchr(s,'=');
+ if (!e) continue;
+
+ *e = 0; /* break the line into 2 parts */
+ v = e+1;
+ k = s;
+
+ /* trim spaces in front of the name/value */
+ while (*k && *k <= 32) k++;
+ while (*v && *v <= 32) v++;
+
+ /* trim spaces everywhere in the name */
+ for (e=k; *e; e++) if (*e <= 32) { *e = 0; break; }
+
+ /* trim spaces only at the end of the value */
+
+ /* http://pecl.php.net/bugs/bug.php?id=14525 */
+ //for (e=v; *e; e++) if (*e <= 32) { *e = 0; break; }
+
+ if (v != NULL) {
+ for (index = strlen(v); index > 0; index--) {
+ if (v[index] > 32) break;
+ v[index] = 0;
+ }
+ }
+ add_assoc_string( return_value, k, v, 1 );
+ }
+ fclose(F);
+ }
+
+ if (filename) efree(filename);
+ return;
+ }
+}
+/* }}} */
+
+/* {{{ uploadprogress_file_php_get_contents
+ */
+static void uploadprogress_file_php_get_contents(char *id, char *fieldname, long maxlen, zval *return_value)
+{
+ char *filename, *template, *contents, *data_identifier;
+ php_stream *stream;
+ int options = ENFORCE_SAFE_MODE;
+ int len, newlen;
+ TSRMLS_FETCH();
+
+ template = INI_STR("uploadprogress.file.contents_template");
+
+ if (strcmp(template, "") == 0) {
+ return;
+ } else {
+ data_identifier = emalloc(strlen(id) + strlen(fieldname) + 2);
+ sprintf(data_identifier, "%s-%s", id, fieldname);
+
+ filename = uploadprogress_mk_filename(data_identifier, template);
+ if (!filename) return;
+
+ stream = php_stream_open_wrapper(filename, "rb", options, NULL);
+ if (!stream) {
+ RETURN_FALSE;
+ }
+
+ /* uses mmap if possible */
+ 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);
+ len = newlen;
+ }
+
+ RETVAL_STRINGL(contents, len, 0);
+ } else if (len == 0) {
+ RETVAL_EMPTY_STRING();
+ } else {
+ RETVAL_FALSE;
+ }
+
+ php_stream_close(stream);
+ if (data_identifier) efree(data_identifier);
+ if (filename) efree(filename);
+
+ return;
+ }
+}
+/* }}} */
+
+#endif /* HAVE_UPLOADPROGRESS */
+
+/*
+* Local variables:
+* tab-width: 4
+* c-basic-offset: 4
+* End:
+* vim600: noet sw=4 ts=4 fdm=marker
+* vim<600: noet sw=4 ts=4
+*/
|