Stream tenant uploads
This commit is contained in:
34
app/Support/UploadStream.php
Normal file
34
app/Support/UploadStream.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UploadStream
|
||||
{
|
||||
/**
|
||||
* Store an uploaded file without loading it fully into memory.
|
||||
*/
|
||||
public static function putUploadedFile(string $disk, string $path, UploadedFile $file): bool
|
||||
{
|
||||
$sourcePath = $file->getRealPath() ?: $file->getPathname();
|
||||
if (! $sourcePath) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$stream = fopen($sourcePath, 'rb');
|
||||
|
||||
if (! $stream) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return Storage::disk($disk)->put($path, $stream);
|
||||
} finally {
|
||||
if (is_resource($stream)) {
|
||||
fclose($stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user