| 1 | <?php |
||
| 2 | |||
| 3 | namespace Dynamic\ImageUpload; |
||
| 4 | |||
| 5 | use SilverStripe\AssetAdmin\Forms\UploadField; |
||
|
0 ignored issues
–
show
|
|||
| 6 | use SilverStripe\Core\Convert; |
||
| 7 | use SilverStripe\Core\Injector\Injector; |
||
| 8 | use SilverStripe\ORM\SS_List; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Class ImageUploadField |
||
| 12 | * @package Dynamic\SilverStripe\ImageUpload |
||
| 13 | */ |
||
| 14 | class ImageUploadField extends UploadField |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var int |
||
| 18 | */ |
||
| 19 | private static $max_upload = 1024000; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | private static $category = 'image/supported'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | private static $allowed_categories = [ |
||
| 30 | 'image/supported', |
||
| 31 | 'image', |
||
| 32 | ]; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * ImageUploadField constructor. |
||
| 36 | * @param string $name |
||
| 37 | * @param null $title |
||
| 38 | * @param SS_List|null $items |
||
| 39 | */ |
||
| 40 | public function __construct($name, $title = null, SS_List $items = null) |
||
| 41 | { |
||
| 42 | parent::__construct($name, $title); |
||
| 43 | |||
| 44 | // set the max upload size |
||
| 45 | $maxUpload = $this->config()->get('max_upload'); |
||
| 46 | $maxPost = Convert::memstring2bytes(ini_get('post_max_size')); |
||
| 47 | $this->getValidator()->setAllowedMaxFileSize(min($maxUpload, $maxPost)); |
||
| 48 | |||
| 49 | // other image specific options |
||
| 50 | $this->setAllowedMaxFileNumber(1); |
||
| 51 | |||
| 52 | $category = static::config()->get('category'); |
||
| 53 | |||
| 54 | if (!in_array($category, $this->config()->get('allowed_categories'))) { |
||
| 55 | $msg = "{$category} not listed in ImageUploadField::allowed_categories. Defaulting to \"image/supported\""; |
||
| 56 | user_error($msg); |
||
| 57 | |||
| 58 | $category = 'image/supported'; |
||
| 59 | } |
||
| 60 | |||
| 61 | $this->setAllowedFileCategories($category); |
||
| 62 | } |
||
| 63 | } |
||
| 64 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths