Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Upload::setAllowedExtensions() is deprecated

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

Page: 1
Go to End
Author Topic: 2919 Views
  • yurigoul
    Avatar
    Community Member
    202 Posts

    Upload::setAllowedExtensions() is deprecated Link to this post

    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

  • Invader_Zim
    Avatar
    Community Member
    141 Posts

    Re: Upload::setAllowedExtensions() is deprecated Link to this post

    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...

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Upload::setAllowedExtensions() is deprecated Link to this post

    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.

  • ss-ss
    Avatar
    Community Member
    15 Posts

    Re: Upload::setAllowedExtensions() is deprecated Link to this post

    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
    {
    }

    2919 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.