7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Uploadify: set Upload Folder
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 4152 Views |
-
Uploadify: set Upload Folder

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? -
Re: Uploadify: set Upload Folder

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 -
Re: Uploadify: set Upload Folder

4 September 2010 at 2:10am Last edited: 4 September 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).
-
Re: Uploadify: set Upload Folder

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 -
Re: Uploadify: set Upload Folder

4 September 2010 at 2:46am Last edited: 4 September 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; -
Re: Uploadify: set Upload Folder

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 -
Re: Uploadify: set Upload Folder

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
-
Re: Uploadify: set Upload Folder

9 September 2010 at 12:27am Last edited: 9 September 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.
| 4152 Views | ||
| Go to Top | Next > |


