Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Bulk uploader on the front end

Go to End

29 Posts   4696 Views


24 May 2009 at 2:36pm Community Member, 215 Posts

Hi guys,

I have a page using the ImageDataObjectManager. This works really well and now I need to extend it to having front end uploading of images.

I envision something similar to the old bulk uploader module using swfuploader and stuff but I don't know how to create dataobjects with the uploaded images and associate them to that page, I also wonder what the best way is to add a title and description.

Ideally i would like it if the same popup that appears in the CMS stepping you through each step could appear on the front end when they click a button.

What are your thoughts on implementing something like this?


24 May 2009 at 3:16pm 4085 Posts

Yeah, I do this all the time. Just create a form with a SWFUploadField. There's a tutorial in the SWFUploadField docs.


1 June 2009 at 1:34am (Last edited: 1 June 2009 1:36am), Community Member, 215 Posts

Hi UncleCheese,
<br >
<br >I have a had a go at doing this myself buy appeared to have failed :( - I've pasted my non-working code here [url][/url] and wonder if you would possibly have time to look over it. I kinda got messed up so not sure what it's finally trying to do - the error is a javascript alert saying "There was a error - file was rejected by server"
<br >
<br >The first function should handle the swf upload files, save them to a folder 'Images' and resize them to 10*10.
<br >
<br >The second function will hopefully attach the uploaded files as data objects to the page from which they were uploaded so that they can be displayed in the ImageGallery.
<br >
<br >Thanks for any advice


1 June 2009 at 4:37am 4085 Posts

Crap, that code is dated. Uploads are handled differently in 2.3. Yours would work great in 2.2! :-)

Here's a working example of a resume upload form I'm using on a site right now:

class EmploymentPage_Controller extends Page_Controller
   public function ResumeForm()
      return new Form(
         new FieldSet(
            new TextField('Name','<span>*</span> Name'),
            new TextField('Address'),
            new TextField('City'),
            new TextField('State'),
            new NumericField('Zip'),
            new EmailField('Email','<span>*</span> Email'),
            new TextField('Phone','<span>*</span> Phone'),
            new TextareaField('Message','<span>*</span> Please use the space below to let us know why you are interested in employment','6','40'),
            new SWFUploadField(
               "<span>*</span> Please attach your most current resume and cover letter (PDF or DOC only).",
               array (
                  'file_types_list' => '*.doc;*.pdf',
                  'file_queue_limit' => '1',
                  'browse_button_text' => 'Choose file...',
                  'upload_url' => $this->Link('handleswfupload'),
                  'required' => 'true'
         new FieldSet(
            new FormAction('doResumeSubmit','Submit Application')
         new RequiredFields('Name','Email','Phone','Message')
   public function handleswfupload()
      if (isset($_FILES["swfupload_file"]) && is_uploaded_file($_FILES["swfupload_file"]["tmp_name"])) {
         $file = new File();
         $u = new Upload();
         $u->loadIntoFile($_FILES['swfupload_file'], $file, "Resumes");
         echo $file->ID;
      else {
         echo ' '; // return something or SWFUpload won't fire uploadSuccess
   public function doResumeSubmit($data,$form)
      $data = $form->getData();
      $to = "";
      $subject = "New Employment Application";
      $from = $data['Email'] ? $data['Email'] : "";
      $email = new Email();
      $email->ss_template = "EmploymentEmail";
      $email->subject = $subject;
      $email->to = $to;
      $email->from = $from;
      if($_POST['uploaded_files']) {
         $file = DataObject::get_by_id("File",$_POST['uploaded_files'][0]);
         $email->attachFile(Director::baseFolder() . "/" . $file->Filename, basename($file->Filename));


10 June 2009 at 4:28pm Community Member, 2 Posts

This works great, but I'm having a issue. I posted your code exactly as it is displayed above. Everything shows up except the upload button. In my template all I do is show resume form.

Any ideas on what would prevent the upload button from being displayed?


11 June 2009 at 1:22am 4085 Posts

Do you have 'requred' => true set on that field? I believe the effect of that is that it hides the upload button until you select a file. If that's not the case, check for javascript errors.


11 June 2009 at 2:33am Community Member, 10 Posts


I have simillar problem, I would like to add some files to a page via frontend. I have a working form with swfupload field (files are uploaded but not attached to a page) and I am able to create new dataobject however without files attached to it. Page has has_many relation with filedataobject manager and I can attach files onlyvia cms. Here is my code:

Front end form

Page where files should be attached

DataObject code:

thanks in advance



11 June 2009 at 2:59am 4085 Posts

What you're trying to do is a little more complicated. It's hard to give you any guidance without seeing the interface, but I think what you want is to create the DataObject in the handleswfupload() function, create the File object, load the $_FILES data into the File object, then link the File object and the DataObject. You can also at that point link the DataObject to whatever page it is on. If the page is dynamic, you'll have to pass the current page ID to the handleswfupload() function using SWFUploadConfig::addPostParams() function.

Go to Top