Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » set max filesize for ImageGallery possible?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3
Go to End
Author Topic: 3418 Views
  • theAlien
    Avatar
    Community Member
    131 Posts

    set max filesize for ImageGallery possible? Link to this post

    Hi,

    My productionserver can't handle GD-imageresizing on large images (it's giving an error, and the only way to solve things is to delete the file manually through directAdmin, which is giving problems with the ImageGallery-db).

    To overcome this problem, I would like to limit the maximum filesize for images uploaded with ImageGallery (or SWFUpload).
    Is this possible and how?

    BTW I found this line in the _config.php of SWFUpload:

    'file_size_limit' => str_replace("M","MB",ini_get('upload_max_filesize')),


    But changing it to for example str_replace("k","kB","500k") will affect all filetypes, and I would like to be able to upload some PDF's and mp3's that are bigger.

  • UncleCheese
    Avatar
    4085 Posts

    Re: set max filesize for ImageGallery possible? Link to this post

    Just add in your _config.php:

    SWFUploadConfig::set_var('file_size_limit','10M');

  • theAlien
    Avatar
    Community Member
    131 Posts

    Re: set max filesize for ImageGallery possible? Link to this post

    But... that's also a general rule, isn't it?

    At least: adding it to image_gallery/_config.php didn't work
    And in swfpload/_config.php the value appears to be used for all filetypes (also PDF and MP3 etc), so I guess it's just another way to say 'file_size_limit' => str_replace("k","kB","500k"),?

    What I'm looking for is something to limit the filesize for specific filetypes, just like in FileField (line 24):

    public $allowedMaxFileSize = array('*' => 3000000, 'jpg' => 400000, 'jpeg' => 400000, 'gif' => 400000, 'png' => 400000);

  • UncleCheese
    Avatar
    4085 Posts

    Re: set max filesize for ImageGallery possible? Link to this post

    Unfortunately that's beyond the capabilities of the SWFUpload right now. That would require expanding the Flash component itself, which is something I know nothing about, but you can put in a request at swfupload.org.

    The only solution that would come close to that is if you added the file_size_limit setting conditionally based on, say, the current controller, but that would be a catch-all solution for all files uploaded to that controller, not a per-file interrogation.

  • theAlien
    Avatar
    Community Member
    131 Posts

    Re: set max filesize for ImageGallery possible? Link to this post

    OK, thanks.
    I already was afraid that it was beyond the capabilities of SWFUpload.

    Do you think it is possible to extend the SWFUpload module and reset the strict upload-limit?
    In that way it would be possible to use SWFUpload for images and SWFUploadExtended for all other files.

  • UncleCheese
    Avatar
    4085 Posts

    Re: set max filesize for ImageGallery possible? Link to this post

    Well, again.. If the controller dictates the file types that are to be expected, then you can work around that.

    mysite/_config.php

    if(Controller::curr()->class == "ImageGalleryManager") // could be wrong on that.. i'm not sure what the controller is of the popup window.
    SWFUploadConfig::set_var('file_size_limit', '10M');

  • theAlien
    Avatar
    Community Member
    131 Posts

    Re: set max filesize for ImageGallery possible? Link to this post

    hmmm...

    I've been trying something like this for some time now. Let me give you all an update:

    1st: I guess SWFUploadConfig::set_var('file_size_limit', '10M'); should be in swfupload/_config.php, if it's placed in mysite/_config.php the upload uses the default file_size_limit that is set through line 10 of swfupload/_config.php.

    2nd: It seems image-gallery has no active current controller (as the notification-message I got already indicated). Testing it with if(Controller::has_curr() == true) echo 'test'; doesn't echo anything, while if(Controller::has_curr() == false) echo 'test'; does... On the other hand, even Page.php doesn't seem to have an active current controller.

    So... after all I'm ending up with the same situation (that's a bit too static for me).
    I'm thinking about either extracting the file-extension of the uploaded file end using it in an if-statement (which seems to be tricky to setup, but very dynamical) or getting the classname of the pagetype and relate to that in the if-statement.

    Maybe there is someone who has another idea?
    Or the night will help my mysterious windows-machine to understand everything I feed it - that would be nice ;-)

  • UncleCheese
    Avatar
    4085 Posts

    Re: set max filesize for ImageGallery possible? Link to this post

    Interesting.. Well this raises a few issues. First, I always thought the mysite/_config.php was executed last, in order to give the user absolute override power. Turns out it runs first, which is pretty lousy. You should never have to modify the _config file of a module. When you upgrade, you'll lose your changes. What a pain. That's what the mysite/_config.php should be used for, but unfortunately, it's getting trumped by the module in this case.

    Also, at the time of execution for _config.php, no controller has been loaded, so you're not able to sniff it out there. Annoying!

    I wonder if there are any other hooks we can use to set that variable. I'll keep thinking about it some more..

    3418 Views
Page: 1 2 3
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.