Skip to content

Commit

Permalink
check if file exists when adding
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Apr 28, 2015
1 parent 5837f07 commit 2e93fab
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/MediaLibraryRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Spatie\MediaLibrary;

use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Spatie\MediaLibrary\FileSystems\FileSystemInterface;
Expand Down Expand Up @@ -29,9 +30,15 @@ public function __construct(FileSystemInterface $fileSystem)
* @param bool $addAsTemporary
*
* @return Media
*
* @throws Exception
*/
public function add($file, MediaLibraryModelInterface $model, $collectionName, $preserveOriginal = false, $addAsTemporary = false)
{
if (! file_exists($file)) {
throw new Exception('File '.$file.' does not exist');
}

$this->addIgnoreFileToMediaLibraryDirectory();

$media = $this->createMediaForFile($file, $collectionName, $addAsTemporary);
Expand Down

0 comments on commit 2e93fab

Please sign in to comment.