Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » SWFUploadFileIFrameField and SS 2.4

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 1828 Views
  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: SWFUploadFileIFrameField and SS 2.4 Link to this post

    It's not really IFrame, but yesterday i decided that it's too hard to add images to the Staff section one by one and i don't like ImageGallery module 'cos it generates thumbs in different way and it's too heavy for example u don't need so more different lightboxes and something else i don't remember, but anyway StaffPage, ContactPage, GalleryImage and etc implents one interface in my code.

    Well, ok:

    StaffHolder:

    function getCMSFields() {
    ..
          $fields = parent::getCMSFields();
    ...
          SWFUploadConfig::addPostParam('ID', $this->ID);
          SWFUploadConfig::addPostParam('Locale', $this->Locale);
          $fields->addFieldToTab("Root.Content.Images",
             new SWFUploadField(
                "EditForm",
                "Upload",
                "",
                array(
                   'file_upload_limit' => 10, // how many files can be uploaded
                   'file_queue_limit' => 10, // how many files can be in the queue at once
                   'browse_button_text' => 'Upload Images ...',
                   'upload_url' => Director::absoluteURL('StaffHolder_Controller/handleswfupload'),
                   'required' => 'true',
                   //'debug' => 'true'
                )
             )
          );

          return $fields;
    ..
       }

    StaffHolder_Controller:

    public function handleswfupload() {
          $parent = DataObject::get_by_id('StaffHolder', $_POST['ID']); // Get parent for permission check
          if( $parent->canCreate(Member::currentUser()) ) { // User Permission Check
          if(isset($_FILES['swfupload_file']) && !empty($_FILES['swfupload_file'])) {
             set_time_limit(1200); // 20 mins
             
             // Assuming its a decendant of File
             $image = new Image();
             if(class_exists("Upload")) {
                $u = new Upload();
                $u->loadIntoFile($_FILES['swfupload_file'], $image);
             }
             else {
                $image->loadUploaded($_FILES['swfupload_file']);
             }
             $image->write(); // Save image
             
             // Page Creating
             $title = substr($_POST['Filename'], 0, strlen($_POST['Filename'])-4); // Get title from file name
             $new = new StaffPage(); // Create new staff page      
             $new->populateDefaults(); // if defaults are set
             $new->setParent($_POST['ID']); // set parent page
             $new -> update(
                array(
                   'MenuTitle' => $title,
                   'Title' => $title,
                   'Locale' => $_POST['Locale'],
                   'PhotoID' => $image->ID // adding image
                )
             );
             $new->writeToStage('Stage'); // Save Page
             die('Image Loaded');
          } else die('Image isn\' sended');
          } else die ('Permission Error');
       }

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