1 <?php
2
3 /* --------------------------------------------------------------
4 ImageFileStorage.inc.php 2015-11-27
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2015 Gambio GmbH
8 Released under the GNU General Public License (Version 2)
9 [http://www.gnu.org/licenses/gpl-2.0.html]
10 --------------------------------------------------------------
11 */
12
13
14 /**
15 * Class AbstractFileStorage
16 *
17 *
18 * @category System
19 * @package Shared
20 * @subpackage Storage
21 */
22 class ImageFileStorage extends AbstractFileStorage
23 {
24 /**
25 * Validates the provided file.
26 *
27 * Validate file extensions are: jpg|jpeg|png|gif|bmp
28 *
29 * @param \ExistingFile $sourceFile The file to validate.
30 *
31 * @throws \InvalidArgumentException
32 *
33 * @return \ImageFileStorage Same instance for chained method calls.
34 */
35 protected function _validateFile(ExistingFile $sourceFile)
36 {
37 $validFileExtension = '/(.)(jpg|jpeg|png|gif|bmp)$/';
38
39 $lowerCasedFilepath = strtolower($sourceFile->getFilePath());
40
41 if(!is_uploaded_file($sourceFile->getFilePath()) && !preg_match($validFileExtension, $lowerCasedFilepath))
42 {
43 throw new \InvalidArgumentException($lowerCasedFilepath . ' has an invalid file extension');
44 }
45 }
46 }