Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Mysterious Upload Directory

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1069 Views
  • eddieconnecti
    Avatar
    Community Member
    26 Posts

    Mysterious Upload Directory Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Mysterious Upload Directory Link to this post

    I don't see any reason why you couldn't just use setUploadFolder("Uploads/articles/images") on your DOM.

  • eddieconnecti
    Avatar
    Community Member
    26 Posts

    Re: Mysterious Upload Directory Link to this post

    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!

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