7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Mysterious Upload Directory
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 962 Views |
-
Mysterious Upload Directory

16 December 2009 at 3:48am
Got a annoying problem by writing files using onBeforeWrite into an specific custom upload folder. I have searched the forum and found some related topics, but none solved the problem i have. This is my class:
class ArticleItems extends DataObject
{static $db = array (
"Description" => "HTMLText",
"ItemType" => "Varchar(50)"
);
static $has_one = array (
"Page" => "Page",
"ImageThumbnailFile" => "Image"
);protected static $itemTypes = array(
"IMAGE" => "Image"
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new DropdownField( "ItemType", "Type of Item", self::$itemTypes ),
new TextareaField( "Description", "Description" ),
new ImageField( "ImageThumbnailFile", "Thumbnail" ),
new FileIFrameField( "DownloadFile", "File for Download" )
);
}
public function onBeforeWrite()
{
$file = $this->ImageThumbnailFile;
$folder = Folder::findOrMake( "Uploads/articles/images" );
if($file && $folder){
if($folder->ID != $file->ParentID){
$file->setParentID($folder->ID);
$file->write();
}
}
parent::onBeforeWrite();
}
}If I uplaod the file, it always stores it in the "Uploads/" Directory. My goal is to resize the image and save the thumbnail in "Uploads/articles/images/thumbnails/". The full sized image should be stored in "Uploads/articles/images" and linked to the Item (not set yet). Has anyone an idea of how to do this? Any idea my help...
-
Re: Mysterious Upload Directory

16 December 2009 at 4:08am
I don't see any reason why you couldn't just use setUploadFolder("Uploads/articles/images") on your DOM.
-
Re: Mysterious Upload Directory

22 December 2009 at 9:39pm
I would like to create three images from the one i upload. This is the reason why i want to set the upload folder for each image. I need a colored thumbnail, a greyscakled thumbnail and an fullsized colored image by maxwidth of 600px. I think it should work with the gd lib. But maybe its better to create an extra class extending the image class with a bunch of methods.
Do you know any examples on writing files, copying files within silverstripe?
And, coming back to your question, where do i set the setUploadFolder?
Thanks!
| 962 Views | ||
|
Page:
1
|
Go to Top |

