2868212fb1eaa65abfbcdb29ae80c5de8009c6c5
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / ViewHelpers / File / SizeViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Install\ViewHelpers\File;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28
29 /**
30 * Get file size from file
31 *
32 * = Examples =
33 *
34 * <code title="Defaults">
35 * <f:file.size>/var/www/typo3/instance/typo3temp/foo.jpg</f:file.size>
36 * </code>
37 * <output>
38 * 1,2k
39 * </output>
40 */
41 class SizeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
42
43 /**
44 * Get size from file
45 *
46 * @param boolean $format If true, file size will be formatted
47 * @throws \TYPO3\CMS\Install\ViewHelpers\Exception
48 * @return integer File size
49 */
50 public function render($format = TRUE) {
51 $absolutePathToFile = $this->renderChildren();
52 if (!is_file($absolutePathToFile)) {
53 throw new \TYPO3\CMS\Install\ViewHelpers\Exception(
54 'File not found',
55 1369563246
56 );
57 }
58 $size = filesize($absolutePathToFile);
59 if ($format) {
60 $size = GeneralUtility::formatSize($size);
61 }
62 return $size;
63 }
64 }