diff --git a/.travis.yml b/.travis.yml index b848430..af96326 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4 before_script: - composer selfupdate diff --git a/composer.json b/composer.json index 290ee84..057ec23 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "description": "File uploading library capable of handling large/chunked/multiple file uploads", "license": "MIT", "autoload": { - "psr-0": { - "FileUpload\\": "src/" + "psr-4": { + "FileUpload\\": "src/FileUpload" } }, "require": { diff --git a/src/FileUpload/FileNameGenerator/Simple.php b/src/FileUpload/FileNameGenerator/Simple.php index 0b0fdcc..2722d7b 100644 --- a/src/FileUpload/FileNameGenerator/Simple.php +++ b/src/FileUpload/FileNameGenerator/Simple.php @@ -56,11 +56,15 @@ public function getFileName($source_name, $type, $tmp_name, $index, $content_ran */ protected function getUniqueFilename($name, $type, $index, $content_range) { + if (! is_array($content_range)) { + $content_range = [0]; + } + while ($this->filesystem->isDir($this->pathresolver->getUploadPath($name))) { $name = $this->pathresolver->upcountName($name); } - $uploaded_bytes = Util::fixIntegerOverflow(intval($content_range[1])); + $uploaded_bytes = Util::fixIntegerOverflow(intval($content_range[1] ?? $content_range[0])); while ($this->filesystem->isFile($this->pathresolver->getUploadPath($name))) { if ($uploaded_bytes == $this->filesystem->getFilesize($this->pathresolver->getUploadPath($name))) { diff --git a/src/FileUpload/FileNameGenerator/Slug.php b/src/FileUpload/FileNameGenerator/Slug.php index dbeafb4..8f88b0c 100644 --- a/src/FileUpload/FileNameGenerator/Slug.php +++ b/src/FileUpload/FileNameGenerator/Slug.php @@ -59,11 +59,15 @@ public function getFileName($source_name, $type, $tmp_name, $index, $content_ran */ protected function getUniqueFilename($name, $type, $index, $content_range) { + if (! is_array($content_range)) { + $content_range = [0]; + } + while ($this->filesystem->isDir($this->pathresolver->getUploadPath($this->getSluggedFileName($name)))) { $name = $this->pathresolver->upcountName($name); } - $uploaded_bytes = Util::fixIntegerOverflow(intval($content_range[1])); + $uploaded_bytes = Util::fixIntegerOverflow(intval($content_range[1] ?? $content_range[0])); while ($this->filesystem->isFile($this->pathresolver->getUploadPath($this->getSluggedFileName($name)))) { if ($uploaded_bytes == $this->filesystem->getFilesize($this->pathresolver->getUploadPath($this->getSluggedFileName($name)))) { @@ -107,7 +111,7 @@ private function slugify($text) $text = strtolower($text); // remove unwanted characters $text = preg_replace('~[^-\w]+~', '', $text); - + if (empty($text)) { return 'n-a'; } diff --git a/tests/FileUpload/FileNameGenerator/MD5Test.php b/tests/FileUpload/FileNameGenerator/MD5Test.php index df57055..6b87f43 100644 --- a/tests/FileUpload/FileNameGenerator/MD5Test.php +++ b/tests/FileUpload/FileNameGenerator/MD5Test.php @@ -11,7 +11,7 @@ class MD5Test extends TestCase { protected $filesystem; - public function setUp() + protected function setUp() { $playground_path = __DIR__ . '/../../playground'; $fixtures_path = __DIR__ . '/../../fixtures'; diff --git a/tests/FileUpload/FileSystem/SimpleTest.php b/tests/FileUpload/FileSystem/SimpleTest.php index fb80d6f..80d690f 100644 --- a/tests/FileUpload/FileSystem/SimpleTest.php +++ b/tests/FileUpload/FileSystem/SimpleTest.php @@ -8,7 +8,7 @@ class SimpleTest extends TestCase { protected $filesystem; - public function setUp() + protected function setUp() { $playground_path = __DIR__ . '/../../playground'; $fixtures_path = __DIR__ . '/../../fixtures'; @@ -42,7 +42,7 @@ public function testWriteToFile() $path = __DIR__ . '/../../playground/test.1.txt'; $this->filesystem->writeToFile($path, $this->filesystem->getFileStream($yadda)); - $this->assertEquals(file_get_contents($yadda), file_get_contents($path)); + $this->assertFileEquals($yadda, $path); $this->filesystem->unlink($path); } diff --git a/tests/FileUpload/FileUploadTest.php b/tests/FileUpload/FileUploadTest.php index 6cfdd74..c6c3857 100644 --- a/tests/FileUpload/FileUploadTest.php +++ b/tests/FileUpload/FileUploadTest.php @@ -6,7 +6,7 @@ class FileUploadTest extends TestCase { - public function setUp() + protected function setUp() { $playground_path = __DIR__ . '/../playground'; $fixtures_path = __DIR__ . '/../fixtures'; diff --git a/tests/FileUpload/Validator/DimensionValidatorTest.php b/tests/FileUpload/Validator/DimensionValidatorTest.php index 84d21e3..2f2af59 100644 --- a/tests/FileUpload/Validator/DimensionValidatorTest.php +++ b/tests/FileUpload/Validator/DimensionValidatorTest.php @@ -297,7 +297,7 @@ public function testSetErrorMessages() ); } - public function setUp() + protected function setUp() { $this->directory = __DIR__ . '/../../fixtures/'; } diff --git a/tests/FileUpload/Validator/MimeTypeValidatorTest.php b/tests/FileUpload/Validator/MimeTypeValidatorTest.php index f4f7f78..2ba6046 100644 --- a/tests/FileUpload/Validator/MimeTypeValidatorTest.php +++ b/tests/FileUpload/Validator/MimeTypeValidatorTest.php @@ -42,7 +42,7 @@ public function testInvalidMimeType() $this->assertFalse($this->validator->validate($file, $_FILES['file']['size'])); } - public function setUp() + protected function setUp() { $this->directory = __DIR__ . '/../../fixtures/'; diff --git a/tests/FileUpload/Validator/SimpleTest.php b/tests/FileUpload/Validator/SimpleTest.php index ede97f2..d898509 100644 --- a/tests/FileUpload/Validator/SimpleTest.php +++ b/tests/FileUpload/Validator/SimpleTest.php @@ -70,7 +70,7 @@ public function testSetErrorMessages() $this->assertEquals($errorMessage, $file->error); } - public function setUp() + protected function setUp() { $this->directory = __DIR__ . '/../../fixtures/'; diff --git a/tests/FileUpload/Validator/SizeValidatorTest.php b/tests/FileUpload/Validator/SizeValidatorTest.php index abf265e..1bf4a1f 100644 --- a/tests/FileUpload/Validator/SizeValidatorTest.php +++ b/tests/FileUpload/Validator/SizeValidatorTest.php @@ -11,7 +11,7 @@ class SizeValidatorTest extends TestCase protected $validator; protected $file; - public function setUp() + protected function setUp() { $this->directory = __DIR__ . '/../../fixtures/';