Skip to content

Commit 5d6c86a

Browse files
drjdrpionl
authored andcommitted
Add support for older Laravel versions with Laravel 7 support
- Laravel 7.0 bug found by and fixed by @drjdr - Added support for older Laravel versions after symfony changes in UploadedFile
1 parent d36213d commit 5d6c86a

File tree

5 files changed

+55
-34
lines changed

5 files changed

+55
-34
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: php
22
php:
3-
- '7.1'
43
- '7.2'
54
- '7.3'
5+
- '7.4'
66
os:
77
- linux
88

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Contribution or overriding
2+
23
Are welcome. To add a new provider just add a new Handler (which extends AbstractHandler). Then implement the chunk
34
upload and progress.
45

56
1. Fork the project.
67
2. Create your bugfix/feature branch and write your (try well-commented) code.
78
3. Commit your changes (and your tests) and push to your branch.
89
4. Create a new pull request against this package's `master` branch.
10+
5. **Test your code in [laravel-chunk-upload-example](https://github.com/pionl/laravel-chunk-upload-example)**.
911

1012
## Pull Requests
1113

@@ -57,4 +59,4 @@ public static function canBeUsedForRequest(Request $request)
5759
Edit the `HandlerFactory` and add your handler to the `$handlers` array
5860

5961
# At runtime or without forking
60-
Call the `HandlerFactory::register($name)` to register your own Handler at runtime and use it
62+
Call the `HandlerFactory::register($name)` to register your own Handler at runtime and use it

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
"test": "./vendor/bin/phpunit"
1616
},
1717
"require": {
18-
"illuminate/http": "5.1 - 5.8|^6.0",
19-
"illuminate/console": "5.1 - 5.8|^6.0",
20-
"illuminate/support": "5.1 - 5.8|^6.0",
21-
"illuminate/filesystem": "5.1 - 5.8|^6.0"
18+
"illuminate/http": "5.2 - 5.8 | ^6.0 | ^7.0",
19+
"illuminate/console": "5.2 - 5.8 | ^6.0 | ^7.0",
20+
"illuminate/support": "5.2 - 5.8 | ^6.0 | ^7.0",
21+
"illuminate/filesystem": "5.2 - 5.8 | ^6.0 | ^7.0"
2222
},
2323
"require-dev": {
24-
"laravel/laravel": "5.1 - 5.8|^6.0",
25-
"phpunit/phpunit": "5.7 || 6.0 || 7.0 || 7.5 || 8.4",
26-
"mockery/mockery": "^1.1.0",
24+
"laravel/laravel": "5.2 - 5.8 | ^6.0 | ^7.0",
25+
"phpunit/phpunit": "5.7 | 6.0 | 7.0 | 7.5 | 8.4 | ^8.5",
26+
"mockery/mockery": "^1.1.0 | ^1.3.0",
2727
"friendsofphp/php-cs-fixer": "^2.16.0",
2828
"overtrue/phplint": "^1.1"
2929
},

readme.md

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Laravel chunked upload
1+
# Laravel Chunk Upload
22

33
[![Total Downloads](https://poser.pugx.org/pion/laravel-chunk-upload/downloads?format=flat)](https://packagist.org/packages/pion/laravel-chunk-upload)
44
[![Build Status](https://travis-ci.org/pionl/laravel-chunk-upload.svg?branch=master)](https://travis-ci.org/pionl/laravel-chunk-upload)
@@ -8,11 +8,15 @@
88

99
## Introduction
1010

11-
Easy to use service/library for chunked upload with supporting multiple JS libraries on top of Laravel's file upload with low memory footprint in mind. Currently supports **Laravel 5+ (with 5.5 Auto discovery)** with features as [cross domains requests](https://github.com/pionl/laravel-chunk-upload/wiki/cross-domain-requests), automatic clean schedule and easy usage.
11+
> Supports Laravel from 5.2 to 7.
1212
13+
Easy to use service/library for chunked upload with supporting multiple JS libraries on top of Laravel's file upload with low memory footprint in mind.
1314

14-
> Currently working on Laravel 7.* support (with older Laraver versions) - change the composer.json repository with desired pull request + new integration testing to help me update the package quicker.
15+
Supports feature as [cross domains requests](https://github.com/pionl/laravel-chunk-upload/wiki/cross-domain-requests), automatic clean schedule and easy usage.
1516

17+
Example repository with integration test can be found in [laravel-chunk-upload-example](https://github.com/pionl/laravel-chunk-upload-example).
18+
19+
> Before adding pull requests read CONTRIBUTION.md
1620
1721
## Installation
1822

@@ -21,26 +25,19 @@ Easy to use service/library for chunked upload with supporting multiple JS libra
2125
```
2226
composer require pion/laravel-chunk-upload
2327
```
24-
25-
**2. Add the service provider (Laravel 5.4 and below - supports Auto discovery)**
26-
27-
```php
28-
\Pion\Laravel\ChunkUpload\Providers\ChunkUploadServiceProvider::class
29-
```
3028

31-
**3. Publish the config (Laravel 5.2 and above, optional)**
29+
**2. Publish the config (Optional)**
3230

3331
```
3432
php artisan vendor:publish --provider="Pion\Laravel\ChunkUpload\Providers\ChunkUploadServiceProvider"
3533
```
3634

37-
3835
## Usage
3936

40-
Setup is composed in 3 steps:
37+
Setup consists of 3 steps:
4138

4239
1. Integrate your controller that will handle the file upload. [How to](https://github.com/pionl/laravel-chunk-upload/wiki/controller)
43-
2. Setting route for the controller. [How to](https://github.com/pionl/laravel-chunk-upload/wiki/routing)
40+
2. Set a route for the controller. [How to](https://github.com/pionl/laravel-chunk-upload/wiki/routing)
4441
2. Choose your front-end provider below (we support multiple providers in single controller)
4542

4643
| Library | Wiki | single & chunk upload | simultaneous uploads | In [example project](https://github.com/pionl/laravel-chunk-upload-example) | Author |
@@ -54,7 +51,7 @@ Setup is composed in 3 steps:
5451

5552
**Simultaneous uploads:** The library must send last chunk as last, otherwise the merging will not work correctly.
5653

57-
**Custom disk:** At this moment I recommend to use the basic storage setup (not linking public folder). It is not tested (Have free time to ensure it is working? PR the changes!).
54+
**Custom disk:** At this moment I recommend using the basic storage setup (not linking public folder). It is not tested (Have free time to ensure it is working? PR the changes!).
5855

5956
For more detailed information (tips) use the [Wiki](https://github.com/pionl/laravel-chunk-upload/wiki) or for working example continue to separate repository with [example](https://github.com/pionl/laravel-chunk-upload-example).
6057

@@ -63,12 +60,28 @@ For more detailed information (tips) use the [Wiki](https://github.com/pionl/lar
6360
Can be found in [releases](https://github.com/pionl/laravel-chunk-upload/releases).
6461

6562
## Contribution or extending
63+
64+
> Read contribution before your PR (and use example repository to run integration tests).
65+
6666
See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute changes. All contributions are welcome.
6767

68+
## Compatibility
69+
70+
* 7.* (last tested on v7.16.1)
71+
* 6.* (last tested on v6.18.20)
72+
* 5.8.* (last tested on v5.8.38)
73+
* 5.7.* (last tested on v5.7.29)
74+
* 5.6.* (last tested on v5.6.40)
75+
* 5.5.* (last tested on v5.5.49)
76+
* 5.4.* (last tested on v5.4.36)
77+
* 5.3.* (last tested on v5.3.31)
78+
* 5.2.* (last tested on v5.2.45)
79+
80+
6881
## Copyright and License
6982

7083
[laravel-chunk-upload](https://github.com/pionl/laravel-chunk-upload)
7184
was written by [Martin Kluska](http://kluska.cz) and is released under the
7285
[MIT License](LICENSE.md).
7386

74-
Copyright (c) 2016-2018 Martin Kluska
87+
Copyright (c) 2016 and beyond Martin Kluska

src/Save/ChunkSave.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Pion\Laravel\ChunkUpload\FileMerger;
99
use Pion\Laravel\ChunkUpload\Handler\AbstractHandler;
1010
use Pion\Laravel\ChunkUpload\Storage\ChunkStorage;
11+
use Symfony\Component\HttpKernel\Kernel as SymfonyKernel;
1112

1213
class ChunkSave extends AbstractSave
1314
{
@@ -217,16 +218,21 @@ protected function buildFullFileFromChunks()
217218
*/
218219
protected function createFullChunkFile($finalPath)
219220
{
220-
return new UploadedFile(
221-
$finalPath,
222-
$this->file->getClientOriginalName(),
223-
$this->file->getClientMimeType(),
224-
filesize($finalPath),
225-
$this->file->getError(),
226-
// we must pass the true as test to force the upload file
227-
// to use a standard copy method, not move uploaded file
228-
true
229-
);
221+
// We must pass the true as test to force the upload file
222+
// to use a standard copy method, not move uploaded file
223+
$test = true;
224+
$clientOriginalName = $this->file->getClientOriginalName();
225+
$clientMimeType = $this->file->getClientMimeType();
226+
$error = $this->file->getError();
227+
228+
// Passing a size as 4th (filesize) argument to the constructor is deprecated since Symfony 4.1.
229+
if (SymfonyKernel::VERSION_ID >= 40100) {
230+
return new UploadedFile($finalPath, $clientOriginalName, $clientMimeType, $error, $test);
231+
}
232+
233+
$fileSize = filesize($finalPath);
234+
235+
return new UploadedFile($finalPath, $clientOriginalName, $clientMimeType, $fileSize, $error, $test);
230236
}
231237

232238
/**

0 commit comments

Comments
 (0)