Roman_applicant-site/app/Services/WorkWithFiles.php

30 lines
811 B
PHP

<?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}";
}
}