Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Using FileIFrameField in the CMS

Go to End

11 Posts   5358 Views

Mr. Matt

Community Member, 5 Posts

1 April 2009 at 11:59am

Edited: 01/04/2009 1:51pm


In the CMS I am trying to use an FileIFrameField and restrict it to only uploading PDF files by doing the following:

$fileUpload = new FileIFrameField( 'PDFUpload', 'PDF Brocure' );
$fileUpload->setAllowedExtensions( array( 'pdf' ) );

$fields->addFieldToTab( 'Root.Content.Main', $fileUpload );

But using this lets me upload any file. Are the extra controls you get e.g. setAllowedExtensions() or setAllowedMaxFileSize() only available in the front end and not the CMS?

Forgot to add also that this is SS 3.2.1 :)




Community Member, 2 Posts

5 August 2009 at 3:10am

I'd like to bump this because I'm having the same problem, albeit outside of CMS. I've installed the blog module and am trying to extend it to allow blog posters to attach an MP3 file. I've gotten this to work with an object of type FileField, and I assume setAllowedExtensions should work on FileIFrameField since it's a subclass of FileField. But, like Mr. Matt, I'm able to attach any type of file. My code is similar to his. This is also on SS version 2.3.1.



Community Member, 8 Posts

18 March 2010 at 11:14pm

Edited: 18/03/2010 11:16pm

I tried to restrict the maximum filesize for a ImageField, but it didn't work (using SilverStripe 2.3.6). I set it to 1 MB, but I was able to upload a picture with over 2 MB.

$navigationImage = new ImageField('NavigationImage', 'Navigation image');
$navigationImage->setAllowedMaxFileSize(array('*' => 1048576));
$fields->addFieldToTab('Root.Content.Navigation', $navigationImage);

To be sure that the documentation of the API is correct and the maximum filesize has to be defined in bytes, I tried some smaller numbers like 100, but I was able to upload my 2 MB picture anyway. Now I would like to know if there is any solution for this problem.


Community Member, 56 Posts

2 August 2010 at 11:13pm

In 2.4+ you want something like;

$f = new FileIFrameField("PDFFileFont","Attached PDF's");
$f->allowedExtensions = $a;

$f_validator = new Upload_Validator();


Community Member, 72 Posts

2 December 2010 at 10:05am

Edited: 02/12/2010 10:12am

when implementing mattclegg's code, I get the following error:

[User Error] Uncaught Exception: Object->__call(): the method 'setvalidator' does not exist on 'FieldSet'

Nevermind, I found my error. I had a type in the setValidator line.


Community Member, 65 Posts

15 April 2011 at 3:21am

Hi mattclegg,

I am trying to allow FileIFrameField to upload mp3 files but am having no luck so far. On my page so far I have the below:


class ProductPage extends Page {
static $db = array(

static $has_one = array(
'CoverArt' => 'Image',
'SampleTrack' => 'File',

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.CoverArt', new ImageField('CoverArt', "Upload image below", null, null, null, "covers"));
$fields->addFieldToTab('Root.Content.SampleTrack', new FileIFrameField('SampleTrack', "Upload MP3 below", null, null, null, "music"));
return $fields;


But I am not sure where I would add in the validator code that you suggested. My FileIFrameField is working as I can import other file types just not mp3.

Any help you can offer would be great.




Community Member, 72 Posts

15 April 2011 at 4:06am

Are you allowing mp3s to be uploaded by setting the allowedExtension?

$fields->allowedExtensions = $a; 

The validator code should go in your getCMSFields() function, just put them after all your addFieldToTab lines but before you return $fields.
I haven't tested that, but it should work for you.


Community Member, 65 Posts

15 April 2011 at 4:14am

Edited: 15/04/2011 4:18am

Hi moloko_man,

Thanks for your reply.

After posting, and I have to say I don't know what I did, but it started working, without adding any new code. I can now upload mp3 files to a 'music' folder I have created within the assets folder.

However, I now can't figure how to get the file to appear on the site and allow users to play the track. I've tried simply adding $SampleTrack as I had done with $CoverArt but it just throws up the 'Sorry, there was a problem with handling your request.' error msg.

Do I need a player? I was hoping just to use either <embed> or <audio>.

UPDATE: Sorry, just thought I should add in the .ss code I am working with:

<div id="ProductPage">
<div id="ProductPageLeftCol">
<div id="Sample">

<div id="ProductPageRightCol">



Go to Top