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