cvs: pear /HTTP_Upload Upload.php package.xml
| From: | Thomas V.V.Cox | Date: | Fri, 25 Jan 2002 15:52:09 +0000 |
| Subject: | cvs: pear /HTTP_Upload Upload.php package.xml | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-2124@lists.php.net to get a copy of this message | ||
cox Fri Jan 25 10:52:09 2002 EDT
Modified files:
/pear/HTTP_Upload Upload.php package.xml
Log:
Fix compatibility with PHP > 4.1 (I though we were going forward
and now I got less info and some things not working).
Go with version 0.8:
- Fixed compatibility issues with PHP > 4.1
- Added isMissing() to the upload main object. Use this first
to check if the user has submitted a file (for PHP > 4.1 users)
- Depreciate the use of errorMsg() in the file object. Use
getMessage() instead.
- Added NL and FR translations (thanks Hans and Luc!)
(full backawards compatibility preserved)
Index: pear/HTTP_Upload/Upload.php
diff -u pear/HTTP_Upload/Upload.php:1.19 pear/HTTP_Upload/Upload.php:1.20
--- pear/HTTP_Upload/Upload.php:1.19 Mon Jan 21 10:22:56 2002
+++ pear/HTTP_Upload/Upload.php Fri Jan 25 10:52:09 2002
@@ -7,7 +7,7 @@
//
// **********************************************
//
-// $Id: Upload.php,v 1.19 2002/01/21 15:22:56 cox Exp $
+// $Id: Upload.php,v 1.20 2002/01/25 15:52:09 cox Exp $
/*
* Pear File Uploader class. Easy and secure managment of files
@@ -24,6 +24,23 @@
* (the new error entry in HTTP_POST_FILES)
* - try to think a way of having all the Error system in other
* file and only include it when an error ocurrs
+*
+* -- Note for users of PHP > 4.1 --
+*
+* Due the fact that PHP now doen't register the HTTP_POST_FILES if no
+* uploads are done, the class is not able to give verbose information
+* about what happens. To check that you have to use the new isMissing()
+* method avaible from the $upload object too. For ex:
+*
+* $upload = new HTTP_Upload('en');
+* $missing = $upload->isMissing();
+* if (!$missing) {
+* <code for manage files>
+* } else {
+* die ($missing->getMessage());
+* }
+*
+* -- Notes --
*/
require_once 'PEAR.php';
@@ -248,10 +265,16 @@
function &_buildFiles()
{
// Form method check
- if (empty($this->post_files) ||
- !ereg('multipart/form-data', $this->content_type)) {
+ if (!ereg('^multipart/form-data', $this->content_type)) {
return $this->raiseError('BAD_FORM');
}
+ // In 4.1 HTTP_POST_FILES isn't initialized when no uploads
+ if (function_exists('version_compare') && version_compare(phpversion(),
'4.1', 'ge')) {
+ $error = $this->isMissing();
+ if (PEAR::isError($error)) {
+ return $error;
+ }
+ }
// Parse $HTTP_POST_FILES
$files = array();
@@ -279,6 +302,22 @@
}
return $files;
}
+
+ /**
+ * Checks if the user submited or not some file
+ *
+ * @return mixed False when are files or PEAR_Error when no files
+ * @access public
+ * @see Read the note in the source code about this function
+ */
+ function isMissing()
+ {
+ if (empty($this->post_files) || count($this->post_files) < 1) {
+ return $this->raiseError('NO_USER_FILE');
+ }
+ return false;
+
+ }
}
/**
@@ -353,6 +392,15 @@
}
}
+ global $HTTP_POST_VARS;
+ // Seems that PHP 4.1.1 doesn't handle the MAX_FILE_SIZE correctly
+ // or I didn't find the new way
+ if (isset($HTTP_POST_VARS['MAX_FILE_SIZE']) &&
+ $size > $HTTP_POST_VARS['MAX_FILE_SIZE'])
+ {
+ $error = 'TOO_LARGE';
+ }
+
$this->upload = array(
'real' => $name,
'name' => $name,
@@ -559,10 +607,21 @@
/**
* Returns a error message, if a error occured
+ * (deprecated) Use getMessage() instead
* @return string a Error message
* @access public
*/
function errorMsg()
+ {
+ return $this->errorCode($this->upload['error']);
+ }
+
+ /**
+ * Returns a error message, if a error occured
+ * @return string a Error message
+ * @access public
+ */
+ function getMessage()
{
return $this->errorCode($this->upload['error']);
}
Index: pear/HTTP_Upload/package.xml
diff -u pear/HTTP_Upload/package.xml:1.6 pear/HTTP_Upload/package.xml:1.7
--- pear/HTTP_Upload/package.xml:1.6 Thu Dec 27 05:32:27 2001
+++ pear/HTTP_Upload/package.xml Fri Jan 25 10:52:09 2002
@@ -13,26 +13,41 @@
<release>
<license>LGPL</license>
- <version>0.7</version>
- <date>2001-12-27</date>
+ <version>0.8</version>
+ <date>2002-1-25</date>
<state>stable</state>
<notes>
-- Added file extension checking support. Now by default rejects this extensions: 'php',
'phtm',
- 'phtml', 'php3', 'inc'
-- More in-line documentation and error code tranlations in spanish, english and german
-- Other minor fixes
+- Fixed compatibility issues with PHP > 4.1
+- Added isMissing() to the upload main object. Use this first
+ to check if the user has submitted a file (for PHP > 4.1 users)
+- Depreciate the use of errorMsg() in the file object. Use
+ getMessage() instead.
+- Added NL and FR translations (thanks Hans and Luc!)
+(full backawards compatibility preserved)
</notes>
- <filelist>
- <dir name="/" baseinstalldir="HTTP">
- <file role="php">Upload.php</file>
- <dir name="docs" role="doc">
- <file>upload_example.php</file>
+ <filelist>
+ <dir name="/" baseinstalldir="HTTP">
+ <file role="php">Upload.php</file>
+ <dir name="docs" role="doc">
+ <file>upload_example.php</file>
+ </dir>
</dir>
- </dir>
- </filelist>
+ </filelist>
</release>
<changelog>
+ <release>
+ <version>0.7</version>
+ <date>2001-12-27</date>
+ <state>stable</state>
+ <notes>
+ - Added file extension checking support. Now by default rejects this extensions:
'php', 'phtm',
+ 'phtml', 'php3', 'inc'
+ - More in-line documentation and error code tranlations in spanish, english and
+ german
+ - Other minor fixes
+ </notes>
+ </release>
<release>
<version>0.6.4</version>
<date>2001-08-15</date>