21491 Posts in 5783 Topics by 2622 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 542 Views |
-
UploadField limiting allowed file extensions

4 July 2012 at 3:44am
Hi all,
I'm still relatively new to SilverStripe and have been trying to get to grips with things since 3.0.0 came out. I'm wondering if there's any way of only allowing certain file types to be uploaded with the UploadField? I can't seem to find anything in the API documentation for it.
I'm interested in limiting it to just images (only for an imaginary client's needs). The 'client' will need to be able to upload hundreds of images per DataObject, so I wasn't sure whether UploadField was the best thing to use.
Thanks
-
Re: UploadField limiting allowed file extensions

4 July 2012 at 5:50am
Try this:
$myField->allowedExtensions = array('jpg', 'gif', 'png');
-
Re: UploadField limiting allowed file extensions

4 July 2012 at 8:01pm
I did try that but I can still upload any type of file :/
This is my implementation of it:
$uploadField = new UploadField('Images');
$uploadField->allowedExtensions = array('jpg', 'gif', 'png');
$fields->addFieldToTab("Root.Images", $uploadField);Thanks
-
Re: UploadField limiting allowed file extensions

5 July 2012 at 11:27pm
Okay, I've fixed this. In case anyone else gets stuck with it:
This
$uploadField->allowedExtensions = array('jpg', 'gif', 'png');
Should instead be this
$uploadField->getValidator()->allowedExtensions = array('jpg', 'gif', 'png');
I need some docs on this!
| 542 Views | ||
|
Page:
1
|
Go to Top |


