Jump to:

23370 Posts in 18160 Topics by 2864 members

General Questions

SilverStripe Forums » General Questions » Cannot set custom folder for ImageField

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2 3
Go to End
Author Topic: 5318 Views
  • blair
    Avatar
    Community Member
    9 Posts

    Cannot set custom folder for ImageField Link to this post

    I have created an Image Field in a HasManyComplexTable popup using the following code:

    new ImageField('Photo', null, null, null, null, "PictureGallery")

    I have attached an image that helps show what the form looks like.

    The problem is that the images uploaded always get saved to 'Uploads' and not the folder I have specified. I inserted a Debug::backtrace() command into the Upload->load(..) method and got the following output from the CMS:

    * Upload->load(Array,)
    Line 152 of Upload.php
    * Upload->loadIntoFile(Array,Object id #57)
    Line 226 of File.php
    * File->loadUploaded(Array)
    Line 123 of Image.php
    * Image->loadUploaded(Array)
    Line 748 of Image.php
    * Image_Uploader->save(Array,Object id #33,Object id #8)
    Line 241 of Form.php
    * Form->httpSubmission(Object id #8)
    Line 129 of RequestHandler.php
    * RequestHandler->handleRequest(Object id #8)
    Line 143 of RequestHandler.php
    * RequestHandler->handleRequest(Object id #8)
    Line 122 of Controller.php
    * Controller->handleRequest(Object id #8)
    Line 277 of Director.php
    * Director::handleRequest(Object id #8,Session)
    Line 121 of Director.php
    * Director::direct(/images/index/PictureGalleryItem/8/Photo/EditImageForm)
    Line 118 of main.php


    As you can see on the first line, the folder path I specified is not being passed into the method. When I look in File.php at the File->loadUploaded(..) method it says that it is deprecated, which seems like it could be the problem.

    Unfortunately, I don't know enough about SS internals to figure out any more from this. Perhaps someone with more expertise could shed some light on this?

    Any help with getting this working correctly would be much appreciated - I'd rather not have all my images being sent to the Uploads folder.

    Attached Files
  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: Cannot set custom folder for ImageField Link to this post

    this may help:

    http://api.silverstripe.com/forms/fields-files/FileField.html#var$folderName

    i think this example should work, but never tried:

    $img = new ImageField('MyImage', 'Please Select an Image');
    $img -> folderName = 'HomePageImages'; //THIS IS RELATIVE TO UPLOADS
    $fields -> addFieldToTab('Root.Content.Image', $img);

  • blair
    Avatar
    Community Member
    9 Posts

    Re: Cannot set custom folder for ImageField Link to this post

    Thanks for that, but unfortunately it still places the image in the 'Uploads' folder.

  • quamsta
    Avatar
    Community Member
    29 Posts

    Re: Cannot set custom folder for ImageField Link to this post

    I'm having the same issue. I can't set the upload directory for ImageField no matter what I do.

  • blair
    Avatar
    Community Member
    9 Posts

    Re: Cannot set custom folder for ImageField Link to this post

    I tried it in a daily build from a couple of weeks ago and it works, so here's hoping 2.3.3 fixes it.

  • freenet
    Avatar
    Community Member
    22 Posts

    Re: Cannot set custom folder for ImageField Link to this post

    I'm using 2.3.3, but problem persists.
    Any ideas?

  • blair
    Avatar
    Community Member
    9 Posts

    Re: Cannot set custom folder for ImageField Link to this post

    It has already been fixed in the daily builds - I'm talking with SS at the moment to find out why it wasn't in 2.3.3.

    Hopefully it will be in the next release.

  • freenet
    Avatar
    Community Member
    22 Posts

    Re: Cannot set custom folder for ImageField Link to this post

    thx answer....
    Need just wait and hope -_-

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