Added error handling of non-image files
This commit is contained in:
parent
56701c78d6
commit
bb6e77191e
@ -60,7 +60,9 @@ class Album extends Model
|
||||
|
||||
public function thumbnailUrl($thumbnailName)
|
||||
{
|
||||
$photo = Photo::where('album_id', $this->id)->first();
|
||||
$photo = $this->photos()
|
||||
->inRandomOrder()
|
||||
->first();
|
||||
|
||||
if (!is_null($photo))
|
||||
{
|
||||
|
@ -98,6 +98,7 @@ class ProcessUploadCommand extends Command
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
$upload->number_failed++;
|
||||
$photo->photo->delete();
|
||||
$photo->delete();
|
||||
}
|
||||
|
||||
@ -128,9 +129,10 @@ class ProcessUploadCommand extends Command
|
||||
|
||||
// Read the Exif data
|
||||
$exifData = @exif_read_data($photoFile);
|
||||
$isExifDataFound = ($exifData !== false && is_array($exifData));
|
||||
$angleToRotate = 0;
|
||||
|
||||
if (isset($exifData['Orientation']))
|
||||
if ($isExifDataFound && isset($exifData['Orientation']))
|
||||
{
|
||||
switch ($exifData['Orientation'])
|
||||
{
|
||||
@ -159,12 +161,16 @@ class ProcessUploadCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
if ($isExifDataFound)
|
||||
{
|
||||
$photo->metadata_version = ProcessUploadCommand::METADATA_VERSION;
|
||||
$photo->taken_at = $this->metadataDateTime($exifData);
|
||||
$photo->camera_make = $this->metadataCameraMake($exifData);
|
||||
$photo->camera_model = $this->metadataCameraModel($exifData);
|
||||
$photo->camera_software = $this->metadataCameraSoftware($exifData);
|
||||
$photo->rotation = $angleToRotate;
|
||||
}
|
||||
|
||||
$photo->save();
|
||||
|
||||
// Generate and save thumbnails
|
||||
|
@ -50,6 +50,11 @@ class ImageHelper
|
||||
{
|
||||
$imageInfo = getimagesize($imagePath);
|
||||
|
||||
if ($imageInfo === false)
|
||||
{
|
||||
throw new \Exception(sprintf('The image "%s" does not appear to be a valid image, or cannot be read', pathinfo($imagePath, PATHINFO_FILENAME)));
|
||||
}
|
||||
|
||||
$im = false;
|
||||
$type = $imageInfo[2];
|
||||
$allowedTypes = [
|
||||
|
@ -71,13 +71,13 @@ class AlbumController extends Controller
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
$this->authorize('admin-access');
|
||||
|
||||
$album = AlbumController::loadAlbum($id);
|
||||
|
||||
return Theme::render('admin.show_album', ['album' => $album]);
|
||||
return Theme::render('admin.show_album', ['album' => $album, 'error' => $request->session()->get('error')]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,7 +102,8 @@ class PhotoController extends Controller
|
||||
$tempFolder = sprintf('%s/btw_upload_%s', env('TEMP_FOLDER', '/tmp'), MiscHelper::randomString());
|
||||
mkdir($tempFolder);
|
||||
|
||||
switch (strtolower($archiveFile->getMimeType()))
|
||||
$mimeType = strtolower($archiveFile->getMimeType());
|
||||
switch ($mimeType)
|
||||
{
|
||||
case 'application/zip':
|
||||
$zip = new \ZipArchive();
|
||||
@ -110,6 +111,10 @@ class PhotoController extends Controller
|
||||
$zip->extractTo($tempFolder);
|
||||
$zip->close();
|
||||
break;
|
||||
|
||||
default:
|
||||
$request->session()->flash('error', sprintf('The file type "%s" is not supported for bulk uploads.', $mimeType));
|
||||
return redirect(route('albums.show', ['id' => $album->id]));
|
||||
}
|
||||
|
||||
$upload = new Upload();
|
||||
@ -121,10 +126,16 @@ class PhotoController extends Controller
|
||||
$upload->save();
|
||||
|
||||
$di = new \RecursiveDirectoryIterator($tempFolder, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$recursive = new \RecursiveIteratorIterator($di);
|
||||
|
||||
/** @var \SplFileInfo $fileInfo */
|
||||
foreach ($di as $fileInfo)
|
||||
foreach ($recursive as $fileInfo)
|
||||
{
|
||||
if ($fileInfo->isDir())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$photoFile = new File($fileInfo->getPathname());
|
||||
|
||||
/** @var File $savedFile */
|
||||
|
@ -10,7 +10,7 @@ class DefaultController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$albums = Album::all()->sortBy('name');
|
||||
$albums = Album::withCount('photos')->get()->sortBy('name');
|
||||
|
||||
return Theme::render('gallery.index', [
|
||||
'albums' => $albums
|
||||
|
@ -10,12 +10,17 @@
|
||||
<div class="panel-heading"><a href="{{ $album->url() }}">{{ $album->name }}</a></div>
|
||||
<div class="panel-body">
|
||||
<p class="text-center">
|
||||
<img class="img-responsive" src="{{ $album->thumbnailUrl('preview') }}"/>
|
||||
@php($albumUrl = $album->thumbnailUrl('preview'))
|
||||
@if (strlen($albumUrl) > 0)
|
||||
<img class="img-responsive" src="{{ $albumUrl }}"/>
|
||||
@endif
|
||||
</p>
|
||||
<p>{{ $album->description }}</p>
|
||||
</div>
|
||||
<div class="panel-footer text-right">
|
||||
<a href="{{ $album->url() }}" class="btn btn-sm btn-default">Open album</a>
|
||||
<div class="panel-footer">
|
||||
<span class="text-left"><b>{{ $album->photos_count }}</b> photos</span>
|
||||
<span class="pull-right"><a href="{{ $album->url() }}" class="btn btn-sm btn-default">Open album</a></span>
|
||||
<span class="clearfix"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -25,6 +25,14 @@
|
||||
@include('themes.base.partials.navbar')
|
||||
|
||||
<div class="container-fluid">
|
||||
@if (isset($error))
|
||||
<div class="container">
|
||||
<div class="alert alert-danger">
|
||||
<strong><i class="fa fa-warning fa-fw"></i></strong> {{ $error }}
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@yield('content')
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user