Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Fix Symfony uploaded file moving #317

Merged
merged 2 commits into from
Jun 10, 2021
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
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