Skip to content

Commit 5b5ac48

Browse files
authored
[1.x] Fix Symfony uploaded file moving (#317)
* fix(symfony): uploaded files moving * make clear
1 parent 411cef2 commit 5b5ac48

5 files changed

+36
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased](https://github.com/laravel/octane/compare/v1.0.4...1.x)
44

5+
### Fixed
6+
- Uploaded files moving ([#317](https://github.com/laravel/octane/pull/317))
57

68
## [v1.0.4 (2021-06-08)](https://github.com/laravel/octane/compare/v1.0.3...v1.0.4)
79

config/octane.php

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Laravel\Octane\Listeners\CollectGarbage;
1515
use Laravel\Octane\Listeners\DisconnectFromDatabases;
1616
use Laravel\Octane\Listeners\EnsureUploadedFilesAreValid;
17+
use Laravel\Octane\Listeners\EnsureUploadedFilesCanBeMoved;
1718
use Laravel\Octane\Listeners\FlushTemporaryContainerInstances;
1819
use Laravel\Octane\Listeners\ReportException;
1920
use Laravel\Octane\Listeners\StopWorkerIfNecessary;
@@ -63,6 +64,7 @@
6364
'listeners' => [
6465
WorkerStarting::class => [
6566
EnsureUploadedFilesAreValid::class,
67+
EnsureUploadedFilesCanBeMoved::class,
6668
],
6769

6870
RequestReceived::class => [

fixes/fix-symfony-file-moving.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// https://github.com/spiral/roadrunner-laravel/issues/43
4+
5+
namespace Symfony\Component\HttpFoundation\File;
6+
7+
function move_uploaded_file($from, $to)
8+
{
9+
return \is_file($from) && \rename($from, $to);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Laravel\Octane\Listeners;
4+
5+
class EnsureUploadedFilesCanBeMoved
6+
{
7+
/**
8+
* Handle the event.
9+
*
10+
* @link https://github.com/spiral/roadrunner-laravel/issues/43
11+
*
12+
* @param mixed $event
13+
* @return void
14+
*/
15+
public function handle($event): void
16+
{
17+
if (! function_exists('\\Symfony\\Component\\HttpFoundation\\File\\move_uploaded_file')) {
18+
require __DIR__.'/../../fixes/fix-symfony-file-moving.php';
19+
}
20+
}
21+
}

src/OctaneServiceProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ protected function bindListeners()
112112
$this->app->singleton(Listeners\EnforceRequestScheme::class);
113113
$this->app->singleton(Listeners\EnsureRequestServerPortMatchesScheme::class);
114114
$this->app->singleton(Listeners\EnsureUploadedFilesAreValid::class);
115+
$this->app->singleton(Listeners\EnsureUploadedFilesCanBeMoved::class);
115116
$this->app->singleton(Listeners\FlushAuthenticationState::class);
116117
$this->app->singleton(Listeners\FlushQueuedCookies::class);
117118
$this->app->singleton(Listeners\FlushSessionState::class);

0 commit comments

Comments
 (0)