Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

[BUG] This fix allows the upload of same filenames in input type file #13

Merged
merged 1 commit into from
Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Transfer/Adapter/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ protected function prepareFiles()

$this->files[$form]['name'] = $form;
foreach ($this->files[$form]['multifiles'] as $key => $value) {
if ($this->files[$value]['tmp_name'] !== '') {
$this->files[$value]['name'] = basename($this->files[$value]['tmp_name']) . '_' . $this->files[$value]['name'];
}
$this->files[$value]['options'] = $this->options;
$this->files[$value]['validated'] = false;
$this->files[$value]['received'] = false;
Expand All @@ -441,6 +444,9 @@ protected function prepareFiles()
}
} else {
$this->files[$form] = $content;
if ($this->files[$form]['tmp_name'] !== '') {
$this->files[$form]['name'] = basename($this->files[$form]['tmp_name']) . '_' . $this->files[$form]['name'];
}
$this->files[$form]['options'] = $this->options;
$this->files[$form]['validated'] = false;
$this->files[$form]['received'] = false;
Expand Down
58 changes: 47 additions & 11 deletions test/Transfer/Adapter/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public function setUp()
{
$_FILES = [
'txt' => [
'name' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt',
'name' => 'test.txt',
'type' => 'plain/text',
'size' => 8,
'tmp_name' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt',
'tmp_name' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'php0zgByO',
'error' => 0]];
$this->adapter = new HttpTestMockAdapter();
}
Expand All @@ -52,7 +52,7 @@ public function tearDown()
public function testEmptyAdapter()
{
$files = $this->adapter->getFileName();
$this->assertContains('test.txt', $files);
$this->assertContains('php0zgByO_test.txt', $files);
}

public function testAutoSetUploadValidator()
Expand Down Expand Up @@ -147,33 +147,69 @@ public function testMultiFiles()
{
$_FILES = [
'txt' => [
'name' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt',
'name' => 'test.txt',
'type' => 'plain/text',
'size' => 8,
'tmp_name' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt',
'tmp_name' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'php0zgByO',
'error' => 0],
'exe' => [
'name' => [
0 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file1.txt',
1 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'],
0 => 'file1.exe',
1 => 'file2.exe'],
'type' => [
0 => 'plain/text',
1 => 'plain/text'],
'size' => [
0 => 8,
1 => 8],
'tmp_name' => [
0 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file1.txt',
1 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'],
0 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'phpqBXGTg',
1 => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'phpZqRDQF'],
'error' => [
0 => 0,
1 => 0]]];
$adapter = new HttpTestMockAdapter();
$adapter->setOptions(['ignoreNoFile' => true]);
$this->assertTrue($adapter->receive('exe'));
$this->assertEquals(
['exe_0_' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file1.txt',
'exe_1_' => __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'],
['exe_0_' => 'phpqBXGTg_file1.exe',
'exe_1_' => 'phpZqRDQF_file2.exe'],
$adapter->getFileName('exe', false));
}


public function testMultiFilesSameName()
{
$_FILES = [
'txt' => [
'name' => 'test.txt',
'type' => 'plain/text',
'size' => 8,
'tmp_name' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'php0zgByO',
'error' => 0
],
'exe' => [
'name' => [
0 => 'file.exe',
1 => 'file.exe'],
'type' => [
0 => 'plain/text',
1 => 'plain/text'],
'size' => [
0 => 8,
1 => 8],
'tmp_name' => [
0 => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'phpOOwDDc',
1 => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'phpDlIxkx'],
'error' => [
0 => 0,
1 => 0]]];
$adapter = new HttpTestMockAdapter();
$adapter->setOptions(['ignoreNoFile' => true]);
$this->assertTrue($adapter->receive('exe'));
$this->assertEquals(
['exe_0_' => 'phpOOwDDc_file.exe',
'exe_1_' => 'phpDlIxkx_file.exe'],
$adapter->getFileName('exe', false));
}

Expand Down
1 change: 0 additions & 1 deletion test/Transfer/Adapter/_files/file2.txt

This file was deleted.

1 change: 1 addition & 0 deletions test/Transfer/Adapter/_files/phpDlIxkx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testfile
1 change: 1 addition & 0 deletions test/Transfer/Adapter/_files/phpOOwDDc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testfile
1 change: 1 addition & 0 deletions test/Transfer/Adapter/_files/phpZqRDQF
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testfile
1 change: 1 addition & 0 deletions test/Transfer/Adapter/_files/phpqBXGTg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testfile