Skip to content

Commit

Permalink
v2.0.7
Browse files Browse the repository at this point in the history
* Fix undefined index when there are no `$_FILES` variable.
  • Loading branch information
ve3 committed Jul 2, 2020
1 parent a4b7ee7 commit 1ac6319
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
20 changes: 18 additions & 2 deletions Rundiz/Upload/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* PHP upload class that is able to validate requirements and limitations, real file's mime type check, detect the errors and report.
*
* @package Upload
* @version 2.0.6
* @version 2.0.7
* @author Vee W.
*
* @property-read array $predefinedErrorMessages Pre-defined error messages.
Expand Down Expand Up @@ -813,8 +813,24 @@ public function upload()
unset($key, $value);
} else {
// if single file upload.
$this->files[$this->input_file_name] = $_FILES[$this->input_file_name];
if (isset($_FILES[$this->input_file_name])) {
// if $_FILES['inputname'] exists. this should be normal situation.
$fileUploaded = $_FILES[$this->input_file_name];
} else {
// if $_FILES['inputname'] is not exists. this is weird situation but can be happens.
// build the array that same as $_FILES for it.
$fileUploaded = array(
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => (int) 4,
'size' => (int) 0,
);
}

$this->files[$this->input_file_name] = $fileUploaded;
$this->files[$this->input_file_name]['input_file_key'] = 0;
unset($fileUploaded);

$result = $this->uploadSingleFile();
}
Expand Down
18 changes: 17 additions & 1 deletion tests/phpunit/ExtendedUploadForTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,24 @@ public function upload()
unset($key, $value);
} else {
// if single file upload.
$this->files[$this->input_file_name] = $_FILES[$this->input_file_name];
if (isset($_FILES[$this->input_file_name])) {
// if $_FILES['inputname'] exists. this should be normal situation.
$fileUploaded = $_FILES[$this->input_file_name];
} else {
// if $_FILES['inputname'] is not exists. this is weird situation.
// build the array that same as $_FILES for it.
$fileUploaded = array(
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => (int) 4,
'size' => (int) 0,
);
}

$this->files[$this->input_file_name] = $fileUploaded;
$this->files[$this->input_file_name]['input_file_key'] = 0;
unset($fileUploaded);

$result = $this->uploadSingleFile();
}
Expand Down
17 changes: 17 additions & 0 deletions tests/phpunit/UploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,23 @@ public function testUploadMultiple()
}// testUploadMultiple


public function testUploadNotSet()
{
// will not set $_FILES and must not contains any error.
unset($_FILES);

$Upload = new \Rundiz\Upload\Tests\ExtendedUploadForTest('filename');
$Upload->upload();

$expect = array(
array(
'code' => 'RDU_4',
)
);
$this->assertArraySubset($expect, $Upload->error_codes);
}// testUploadNotSet


public function testUploadSingle()
{
$_FILES = $this->file_51kbimage;
Expand Down

0 comments on commit 1ac6319

Please sign in to comment.