PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / trunk
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance vtrunk
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / webp-convert / src / Convert / Converters / ConverterTraits / CloudConverterTrait.php

CloudConverterTrait.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance trunk, at vendor/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/CloudConverterTrait.php

73 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WebPConvert\Convert\Converters\ConverterTraits;
4
5 use WebPConvert\Convert\Exceptions\ConversionFailedException;
6 use WebPConvert\Convert\Converters\AbstractConverter;
7 use WebPConvert\Convert\Helpers\PhpIniSizes;
8
9 /**
10 * Trait for converters that works by uploading to a cloud service.
11 *
12 * The trait adds a method for checking against upload limits.
13 *
14 * @package WebPConvert
15 * @author Bjørn Rosell <[email protected]>
16 * @since Class available since Release 2.0.0
17 */
18 trait CloudConverterTrait
19 {
20
21 /**
22 * Test that filesize is below "upload_max_filesize" and "post_max_size" values in php.ini.
23 *
24 * @param string $iniSettingId Id of ini setting (ie "upload_max_filesize")
25 *
26 * @throws ConversionFailedException if filesize is larger than the ini setting
27 * @return void
28 */
29 private function checkFileSizeVsIniSetting($iniSettingId)
30 {
31 $fileSize = @filesize($this->source);
32 if ($fileSize === false) {
33 return;
34 }
35 $sizeInIni = PhpIniSizes::getIniBytes($iniSettingId);
36 if ($sizeInIni === false) {
37 // Not sure if we should throw an exception here, or not...
38 return;
39 }
40 if ($sizeInIni < $fileSize) {
41 throw new ConversionFailedException(
42 'File is larger than your ' . $iniSettingId . ' (set in your php.ini). File size:' .
43 round($fileSize / 1024) . ' kb. ' .
44 $iniSettingId . ' in php.ini: ' . ini_get($iniSettingId) .
45 ' (parsed as ' . round($sizeInIni / 1024) . ' kb)'
46 );
47 }
48 }
49
50 /**
51 * Check convertability of cloud converters (that file is not bigger than limits set in php.ini).
52 *
53 * Performs the same as ::Convertability(). It is here so converters that overrides the
54 * ::Convertability() still has a chance to do the checks.
55 *
56 * @throws ConversionFailedException if filesize is larger than "upload_max_filesize" or "post_max_size"
57 * @return void
58 */
59 public function checkConvertabilityCloudConverterTrait()
60 {
61 $this->checkFileSizeVsIniSetting('upload_max_filesize');
62 $this->checkFileSizeVsIniSetting('post_max_size');
63 }
64
65 /**
66 * Check convertability of cloud converters (file upload limits).
67 */
68 public function checkConvertability()
69 {
70 $this->checkConvertabilityCloudConverterTrait();
71 }
72 }
73