Roman_applicant-site/app/Services/WorkWithFiles.php

30 lines
811 B
PHP
Raw Permalink Normal View History

2024-01-26 11:15:11 +03:00
<?php
namespace App\Services;
use Carbon\Carbon;
class WorkWithFiles
{
public static function saveFileToUploads($content)
{
$destinationPath = 'uploads';
$content->move($destinationPath, $content->getClientOriginalName());
}
public static function renameFile($content)
{
$nameChunks = explode('.', $content->getClientOriginalName());
array_splice($nameChunks, 1);
$timestamp = Carbon::now();
$name = implode('.', $nameChunks);
$newName = "{$name}{$timestamp}.{$content->getClientOriginalExtension()}";
$dir = __DIR__;
$path = "{$dir}/../../public/uploads/";
$oldName = $content->getClientOriginalName();
rename("{$path}{$oldName}", "{$path}{$newName}");
return "{$path}{$newName}";
}
}