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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Uploadify: set Upload Folder


Go to End


9 Posts   7478 Views

Avatar
oleze

Community Member, 65 Posts

3 September 2010 at 7:36am

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?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

3 September 2010 at 8:38am

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

Avatar
oleze

Community Member, 65 Posts

4 September 2010 at 2:10am

Edited: 04/09/2010 2:33am

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

4 September 2010 at 2:36am

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

Avatar
oleze

Community Member, 65 Posts

4 September 2010 at 2:46am

Edited: 04/09/2010 2:49am

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;

Avatar
UncleCheese

Forum Moderator, 4102 Posts

4 September 2010 at 2:59am

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

Avatar
Carbon Crayon

Community Member, 598 Posts

8 September 2010 at 11:21pm

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

Avatar
bummzack

Community Member, 904 Posts

9 September 2010 at 12:27am

Edited: 09/09/2010 12:51am

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.

Go to Top