PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTTP » HTTP_Upload » Bug #1641

isValid()/isError() semantics

Details

Submitted2004-06-15 04:12 UTC
Frommhavilah at hotmail dot com
Assignedwenz
StatusClosed
PackageHTTP_Upload
PHP Version4.3.6
OSWinXP
Roadmaps(Not assigned)

Comments

[2004-06-15 04:12 UTC] mhavilah at hotmail dot com

Description:
------------
When using the HTTP::Upload routines, if you try to upload a non-existant/empty client-side file, the routines do not correctly generate an error.

HTTP::Upload->isValid() returns true when it should return false.

As an example: Here is a dump of a file object's properties...
----start source excerpt-----------
$fileRef = $upload->getFiles(...)
...
$propertiesArray = $fileRef->getProp();
...
----end source---------------------
----stdout excerpt-----------------
Jun 15 13:41:46 contentUploadAction [info] Uploaded File properties:array (
'real' => 'dcvsdfsdrfsd',
'name' => '541940ce6ff9e79a9.',
'form_name' => 'filenameField',
'ext' => '',
'tmp_name' => 'C:\\WINDOWS\\TEMP\\php85.tmp',
'size' => 0,
'type' => 'application/octet-stream',
'error' => NULL,
)
---end stdout----------------------
You can see in the above array, 'real' name is a bogus/non-existant client-side filename, but error == NULL, hence isValid() returns true.

If there is no way to detect this error condition, perhaps a helper method named isEmpty() should be provided.
For example:

function isEmpty()
{
if ($this->upload['size'] == 0)
return true;
else
return false;
}

Note also: isError() currently is hardcoded to just check for the file TOO_LARGE error scenario. [See code attachment]

Perhaps this could be renamed and/or changed to check for zero-sized file uploads.

Reproduce code:
---------------
#=====HTTP/Upload.php====excerpt-start====
function isValid()
{
if ($this->upload['error'] === null) {
return true;
}
return false;
}
.....
/**
* Some error occured during upload (most common due a file size problem,
* like max size exceeded or 0 bytes long).
* ....
**/
function isError()
{
// MiH-suggestion:
// if ($this->upload['size'] == '0') ||
if ($this->upload['error'] == 'TOO_LARGE') {
return true;
}
return false;
}
#=====HTTP/Upload.php====excerpt-start====

Expected result:
----------------
If you try to upload a non-existant client-side file, some sort of error should be flagged.

isValid() probably shouldnt return true.
isError() probably shouldnt return false

isEmpty() - if available - would return true

Actual result:
--------------
HTTP::Upload->isValid() returns true when it should return false.

[2004-06-16 14:38 UTC] cox at idecnet dot com

In PHP <= 4.1 AFAIR, you got 0 size when the file exceded the max allowed size. Dunno how is the current behaviour after Jani's rewrite (in 4.2 AFAIR again :)

Anyway, isEmpty() is overkill, just an error should be enough.

Tomas V.V.Cox