Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Uploadify: set Upload Folder

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 5164 Views
  • oleze
    Avatar
    Community Member
    64 Posts

    Uploadify: set Upload Folder Link to this post

    Hi there,
    I switched my File- and ImageFields to the new File-/ImageUploadFields. I would like to set my Upload-Folder and tried

    $layoutphoto = new ImageUploadField('LayoutPhoto');
    $layoutphoto->setVar("uploadFolder","'assets/layout_images/'.$this->URLSegment");

    but this code doesn't work.
    Can somebody (Uncle Cheese ;) ) help me?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify: set Upload Folder Link to this post

    Actually for that you can just use $uploader->uploadFolder = "some-folder";

    Don't forget to remove "assets/" because the upload paths are always relative to that.

    Also, make sure you're on the latest version because the pathing underwent some changes today.

    ----------------
    Silverstripe tips, tutorials, screencasts, and more.. http://www.leftandmain.com

  • oleze
    Avatar
    Community Member
    64 Posts

    Re: Uploadify: set Upload Folder Link to this post

    Thanks, but doesn't that change the Upload folder for all Uploads within this page?
    (I'm using multiple upload-fields within that page-type, all organized to different folders.)

    I solved this by adding a function to UploadifyField.php:

    public function setUploadFolder($folder) {
          $this->uploadFolder = $folder;
       }

    and then I changed my code in getCMSFields() to

    $layoutphoto = new ImageUploadField('LayoutPhoto');
    $layoutphoto->removeFolderSelection();
    $layoutphoto->setUploadFolder('layout_images/'.$this->URLSegment);

    and with that, I can change the folder for every instance of UploadFields although it lacks the ability for updates of the Uploadify-Module (as long as you don't implement the function to the core of the module).

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify: set Upload Folder Link to this post

    No, that's not accurate. $uploader->uploadFolder = "some-folder"; will set the property at an instance level. If you had set a class property like UploadifyField::$upload_folder, that would affect all instances, but the instances always override the class properties anyway. The function you've added is not necessary.

    ----------------
    Silverstripe tips, tutorials, screencasts, and more.. http://www.leftandmain.com

  • oleze
    Avatar
    Community Member
    64 Posts

    Re: Uploadify: set Upload Folder Link to this post

    Well, your method works as long as I have a static upload-folder that doesn't depend on the name of the current page (as I would like to), perhaps I got something wrong in the code? (Yes I got, the "" are not necessary)

    // works
    $layoutphoto->uploadFolder = "layout_images/";

    // works too
    $layoutphoto->uploadFolder = 'layout_images/'.$this->URLSegment;

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify: set Upload Folder Link to this post

    Right. But my point is that you're not setting anything globally. Both of those examples affect the instance, not the class itself. Whether you're using dynamic properties of the current controller is irrelevant.

    ----------------
    Silverstripe tips, tutorials, screencasts, and more.. http://www.leftandmain.com

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Uploadify: set Upload Folder Link to this post

    Just noticed that if you try to set the uploadFolder before you call removeFolderSelection, then it defaults to 'Uploads', while setting it after will work:

    //DOES NOT WORK - Uploads to 'Uploads'
    $FilesField->uploadFolder = 'Uploads/myFolder';
    $FilesField->removeFolderSelection();

    //WORKS - Uploads to 'Uploads/myFolder'
    $FilesField->removeFolderSelection();
    $FilesField->uploadFolder = 'Uploads/myFolder';

    This is because on line 596 of UploadifyField the uploadFolder is reset to 'Uploads'. Is that a neccacery step? Or am I using the wront function to remove the folderSelection?

    Ok looking at it perhaps I should be using:

    $FilesField->allowFolderSelection = false;

    Aram

    -------------------------------------------------------------------------

    www.ssbits.com - Silverstripe Tuorials, Tips and other bits

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Uploadify: set Upload Folder Link to this post

    I'm doing it the same way as Aram does and this seems to be the (only?) way to make this work properly.

    Btw.: I noticed the setUploadFolder on the DOM does no longer exist? If I have a FileUploadField on my DataObject with a defined folder (as described by Aram), will the DOM pick up the upload-folder?

    Update: to clarify: By "DOM" I mean the FileDataObjectManager and ImageDataObjectManager, where you upload files prior to editing the DataObjects.

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