blue-twilight/app/AlbumSources/LocalFilesystemSource.php

46 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\AlbumSources;
use App\Album;
use App\Helpers\MiscHelper;
use App\Photo;
use Symfony\Component\HttpFoundation\File\File;
class LocalFilesystemSource implements IAlbumSource
{
private $parentFolder;
public function __construct($parentFolder)
{
$this->parentFolder = $parentFolder;
}
public function getPathToPhoto(Album $album, Photo $photo)
{
return sprintf('%s/%s', $this->getPathToAlbum($album), $photo->file_name);
}
public function saveThumbnail(Album $album, Photo $photo, $thumbnailImageResource, $thumbnailInfo)
{
}
public function saveUploadedPhoto(Album $album, File $uploadedFile)
{
$tempFilename = sprintf('%s/photo_%s', $this->getPathToAlbum($album), MiscHelper::randomString(20));
$extension = $uploadedFile->guessExtension();
if (!is_null($extension))
{
$tempFilename .= '.' . $extension;
}
$uploadedFile->move(dirname($tempFilename), basename($tempFilename));
return new File($tempFilename);
}
private function getPathToAlbum(Album $album)
{
return sprintf('%s/albums/%s', $this->parentFolder, $album->url_alias);
}
}