Skip to content

Commit

Permalink
[1.x] Fix Symfony uploaded file moving (#317)
Browse files Browse the repository at this point in the history
* fix(symfony): uploaded files moving

* make clear
  • Loading branch information
tarampampam authored Jun 10, 2021
1 parent 411cef2 commit 5b5ac48
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

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

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

Expand Down
2 changes: 2 additions & 0 deletions config/octane.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Laravel\Octane\Listeners\CollectGarbage;
use Laravel\Octane\Listeners\DisconnectFromDatabases;
use Laravel\Octane\Listeners\EnsureUploadedFilesAreValid;
use Laravel\Octane\Listeners\EnsureUploadedFilesCanBeMoved;
use Laravel\Octane\Listeners\FlushTemporaryContainerInstances;
use Laravel\Octane\Listeners\ReportException;
use Laravel\Octane\Listeners\StopWorkerIfNecessary;
Expand Down Expand Up @@ -63,6 +64,7 @@
'listeners' => [
WorkerStarting::class => [
EnsureUploadedFilesAreValid::class,
EnsureUploadedFilesCanBeMoved::class,
],

RequestReceived::class => [
Expand Down
10 changes: 10 additions & 0 deletions fixes/fix-symfony-file-moving.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

// https://github.com/spiral/roadrunner-laravel/issues/43

namespace Symfony\Component\HttpFoundation\File;

function move_uploaded_file($from, $to)
{
return \is_file($from) && \rename($from, $to);
}
21 changes: 21 additions & 0 deletions src/Listeners/EnsureUploadedFilesCanBeMoved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Laravel\Octane\Listeners;

class EnsureUploadedFilesCanBeMoved
{
/**
* Handle the event.
*
* @link https://github.com/spiral/roadrunner-laravel/issues/43
*
* @param mixed $event
* @return void
*/
public function handle($event): void
{
if (! function_exists('\\Symfony\\Component\\HttpFoundation\\File\\move_uploaded_file')) {
require __DIR__.'/../../fixes/fix-symfony-file-moving.php';
}
}
}
1 change: 1 addition & 0 deletions src/OctaneServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ protected function bindListeners()
$this->app->singleton(Listeners\EnforceRequestScheme::class);
$this->app->singleton(Listeners\EnsureRequestServerPortMatchesScheme::class);
$this->app->singleton(Listeners\EnsureUploadedFilesAreValid::class);
$this->app->singleton(Listeners\EnsureUploadedFilesCanBeMoved::class);
$this->app->singleton(Listeners\FlushAuthenticationState::class);
$this->app->singleton(Listeners\FlushQueuedCookies::class);
$this->app->singleton(Listeners\FlushSessionState::class);
Expand Down

0 comments on commit 5b5ac48

Please sign in to comment.