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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Upload::setAllowedExtensions() is deprecated


Go to End


4 Posts   4589 Views

Avatar
yurigoul

Community Member, 203 Posts

4 April 2010 at 2:52am

Edited: 04/04/2010 2:54am

When trying to control the file types that can be uploaded in a File -i get the following message:

ERROR [User Notice]: Upload::setAllowedExtensions() is deprecated. Please use Upload_Validator::setAllowedExtensions() instead

Anybody has the scoop on this one?

I have been looking in the forums docs and in my sites code, but it is not clear to me how to use Upload_Validator::setAllowedExtensions()

EDIT: am using 2.4 beta2

Avatar
Invader_Zim

Community Member, 141 Posts

6 April 2010 at 4:05am

Edited: 06/04/2010 4:09am

I am using 2.4.0rc1 and i'm currently staring at the same error message.
It seems to me that there is no Upload_Validator class in sapphire... oO /confused...

Edit: Arrgh, found Upload_Validator; it's in Upload.php as well...

Avatar
timwjohn

Community Member, 98 Posts

10 April 2010 at 3:58am

Contrary to the notice, it's actually Upload_Validator->setAllowedExtensions(). For those interested, here's how I got it working:

		$image = new FileIFrameField('CarouselImage', 'Carousel Image (JPEG files only)');
		$image->allowedExtensions = array('jpg', 'jpeg');
		$image_validator = new Upload_Validator();
		$image_validator->setAllowedExtensions(array('jpg', 'jpeg'));
		$image->setValidator($image_validator);
		$fields->replaceField('CarouselImage', $image);

This replaced an existing image field in ModelAdmin. It only performs validation on the server side. Am I right in thinking it should be possible to limit file types in the file upload dialog box too? Cos I haven't been able to figure it out... SWFUpload can do it, but I'm getting a Class 'Image_Uploader' not found error when trying to use it in ModelAdmin.

Avatar
SS SS

Community Member, 24 Posts

3 May 2012 at 4:05am

ERROR [User Notice]: Upload::setAllowedExtensions() is deprecated. Please use Upload_Validator::setAllowedExtensions() instead

Getting same sort of error while using the following code from ssbits.com on the following URL:

http://www.ssbits.com/tutorials/2009/embed-flash-content-using-swfobject/

<?php
class FlashPage extends Page
{
public static $db = array(
'AlternateContent' => 'HTMLText'
);

public static $has_one = array(
'FlashFile' => 'File'
);

public function getCMSFields(){
$fields = parent::getCMSFields();

// create a file upload field that only allows swf to be uploaded
$fileUpload = new FileIFrameField('FlashFile', 'Flash file (swf)');
$fileUpload->setAllowedExtensions(array('swf'));

$fields->addFieldsToTab('Root.Content.Flash', array(
$fileUpload,
new HtmlEditorField('AlternateContent', 'Flash replacement text', 20)
));

return $fields;
}
}
class FlashPage_Controller extends Page_Controller
{
}