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)
|
public function thumbnailUrl($thumbnailName)
|
||||||
{
|
{
|
||||||
$photo = Photo::where('album_id', $this->id)->first();
|
$photo = $this->photos()
|
||||||
|
->inRandomOrder()
|
||||||
|
->first();
|
||||||
|
|
||||||
if (!is_null($photo))
|
if (!is_null($photo))
|
||||||
{
|
{
|
||||||
|
@ -98,6 +98,7 @@ class ProcessUploadCommand extends Command
|
|||||||
catch (\Exception $ex)
|
catch (\Exception $ex)
|
||||||
{
|
{
|
||||||
$upload->number_failed++;
|
$upload->number_failed++;
|
||||||
|
$photo->photo->delete();
|
||||||
$photo->delete();
|
$photo->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,9 +129,10 @@ class ProcessUploadCommand extends Command
|
|||||||
|
|
||||||
// Read the Exif data
|
// Read the Exif data
|
||||||
$exifData = @exif_read_data($photoFile);
|
$exifData = @exif_read_data($photoFile);
|
||||||
|
$isExifDataFound = ($exifData !== false && is_array($exifData));
|
||||||
$angleToRotate = 0;
|
$angleToRotate = 0;
|
||||||
|
|
||||||
if (isset($exifData['Orientation']))
|
if ($isExifDataFound && isset($exifData['Orientation']))
|
||||||
{
|
{
|
||||||
switch ($exifData['Orientation'])
|
switch ($exifData['Orientation'])
|
||||||
{
|
{
|
||||||
@ -159,12 +161,16 @@ class ProcessUploadCommand extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$photo->metadata_version = ProcessUploadCommand::METADATA_VERSION;
|
if ($isExifDataFound)
|
||||||
$photo->taken_at = $this->metadataDateTime($exifData);
|
{
|
||||||
$photo->camera_make = $this->metadataCameraMake($exifData);
|
$photo->metadata_version = ProcessUploadCommand::METADATA_VERSION;
|
||||||
$photo->camera_model = $this->metadataCameraModel($exifData);
|
$photo->taken_at = $this->metadataDateTime($exifData);
|
||||||
$photo->camera_software = $this->metadataCameraSoftware($exifData);
|
$photo->camera_make = $this->metadataCameraMake($exifData);
|
||||||
$photo->rotation = $angleToRotate;
|
$photo->camera_model = $this->metadataCameraModel($exifData);
|
||||||
|
$photo->camera_software = $this->metadataCameraSoftware($exifData);
|
||||||
|
$photo->rotation = $angleToRotate;
|
||||||
|
}
|
||||||
|
|
||||||
$photo->save();
|
$photo->save();
|
||||||
|
|
||||||
// Generate and save thumbnails
|
// Generate and save thumbnails
|
||||||
|
@ -50,6 +50,11 @@ class ImageHelper
|
|||||||
{
|
{
|
||||||
$imageInfo = getimagesize($imagePath);
|
$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;
|
$im = false;
|
||||||
$type = $imageInfo[2];
|
$type = $imageInfo[2];
|
||||||
$allowedTypes = [
|
$allowedTypes = [
|
||||||
|
@ -71,13 +71,13 @@ class AlbumController extends Controller
|
|||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show(Request $request, $id)
|
||||||
{
|
{
|
||||||
$this->authorize('admin-access');
|
$this->authorize('admin-access');
|
||||||
|
|
||||||
$album = AlbumController::loadAlbum($id);
|
$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());
|
$tempFolder = sprintf('%s/btw_upload_%s', env('TEMP_FOLDER', '/tmp'), MiscHelper::randomString());
|
||||||
mkdir($tempFolder);
|
mkdir($tempFolder);
|
||||||
|
|
||||||
switch (strtolower($archiveFile->getMimeType()))
|
$mimeType = strtolower($archiveFile->getMimeType());
|
||||||
|
switch ($mimeType)
|
||||||
{
|
{
|
||||||
case 'application/zip':
|
case 'application/zip':
|
||||||
$zip = new \ZipArchive();
|
$zip = new \ZipArchive();
|
||||||
@ -110,6 +111,10 @@ class PhotoController extends Controller
|
|||||||
$zip->extractTo($tempFolder);
|
$zip->extractTo($tempFolder);
|
||||||
$zip->close();
|
$zip->close();
|
||||||
break;
|
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();
|
$upload = new Upload();
|
||||||
@ -121,10 +126,16 @@ class PhotoController extends Controller
|
|||||||
$upload->save();
|
$upload->save();
|
||||||
|
|
||||||
$di = new \RecursiveDirectoryIterator($tempFolder, \RecursiveDirectoryIterator::SKIP_DOTS);
|
$di = new \RecursiveDirectoryIterator($tempFolder, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||||
|
$recursive = new \RecursiveIteratorIterator($di);
|
||||||
|
|
||||||
/** @var \SplFileInfo $fileInfo */
|
/** @var \SplFileInfo $fileInfo */
|
||||||
foreach ($di as $fileInfo)
|
foreach ($recursive as $fileInfo)
|
||||||
{
|
{
|
||||||
|
if ($fileInfo->isDir())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$photoFile = new File($fileInfo->getPathname());
|
$photoFile = new File($fileInfo->getPathname());
|
||||||
|
|
||||||
/** @var File $savedFile */
|
/** @var File $savedFile */
|
||||||
|
@ -10,7 +10,7 @@ class DefaultController extends Controller
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$albums = Album::all()->sortBy('name');
|
$albums = Album::withCount('photos')->get()->sortBy('name');
|
||||||
|
|
||||||
return Theme::render('gallery.index', [
|
return Theme::render('gallery.index', [
|
||||||
'albums' => $albums
|
'albums' => $albums
|
||||||
|
@ -10,12 +10,17 @@
|
|||||||
<div class="panel-heading"><a href="{{ $album->url() }}">{{ $album->name }}</a></div>
|
<div class="panel-heading"><a href="{{ $album->url() }}">{{ $album->name }}</a></div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p class="text-center">
|
<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>
|
||||||
<p>{{ $album->description }}</p>
|
<p>{{ $album->description }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-footer text-right">
|
<div class="panel-footer">
|
||||||
<a href="{{ $album->url() }}" class="btn btn-sm btn-default">Open album</a>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -25,6 +25,14 @@
|
|||||||
@include('themes.base.partials.navbar')
|
@include('themes.base.partials.navbar')
|
||||||
|
|
||||||
<div class="container-fluid">
|
<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')
|
@yield('content')
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user