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

Cant get SWFUploadField to work on front end


5 Posts   1749 Views


Community Member, 10 Posts

12 July 2009 at 11:40pm

First off, hello everyone.

I have been using SilverStripe for about a month or two now and have been loving it, and after trawling through the docs and forum I have learned quite a bit and built a bunch of modules (heh coming soon to this site).

But now I have hit a wall.

I am trying to use a SWFUploadField on a front end page but cant get it to work and I need some help!

Here is my code

function editGallery(){
   $member = Member::currentUser();
   $res = "<br /><strong>Usage:</strong><br />
   <ul><li>Images must be web jpgs</li>
   <li>Max width: 600 pixels</li>
   <li>Max height: 700 pixels</li>
   <li>Uploaded files larger than the restrictions will be resized accordingly</li>
   $folderDir = "assets/$member->ProfileURL/";
   $fields = new FieldSet(   
      new LiteralField("fileUpload",$res),
      new SWFUploadField("editGallery","Image","Upload files",
array (
'file_types_list' => '*.jpg',
'file_queue_limit' => '15',
'browse_button_text' => 'Choose images...',
'upload_url' => $this->Link('handleswfupload'),
'required' => 'true',
'button_image_url' => '/swfupload/images/upload_button_new.png'
      $actions = new FieldSet(new FormAction("uploadGallery", "Submit"));
      $validator = new RequiredFields("Image");
      return new Form($this,'editGallery', $fields, $actions, $validator);

   // form helpers
   function handleswfupload(){
      $member = Member::currentUser();
      $folderDir = "Users/$member->ProfileURL/";
      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, $folderDir);
         echo $file->ID;
      else{echo ' ';}

Where am I going wrong?


Forum Moderator, 4096 Posts

14 July 2009 at 1:08am

I need more to go on than "it doesn't work." What is it not doing? Are there any errors?


Community Member, 10 Posts

15 July 2009 at 12:35pm

Well basically I press the submit button for my form and then the page goes through the SS form processing and the if statement -

if(isset($_FILES["swfupload_file"]) && is_uploaded_file($_FILES["swfupload_file"]["tmp_name"]))

returns false and nothing goes through- no error messages are reported in dev mode or anything.

I can use regular form fields and such and they upload files fine but when I use this one I have no indication of what went wrong.

Is there no obvious reason why the field isnt uploading things?


Forum Moderator, 4096 Posts

15 July 2009 at 1:47pm

Out of curiosity, how did you confirm that that if block is failing? Are you using the SWFUpload debug mode?


Community Member, 10 Posts

15 July 2009 at 7:12pm

The problem was with my code, and the SWF debug helped me find that (wish I saw it earlier).

The error was with something I am building into my pages, a tinyURL type system. Problem was that I had an array of things to ignore as part of that system, and I had "handleswfupload" ignored but not "handleswfupload#". Whoopsy.

Also noticed that there was r212 out and I was using r197 (from extensions/module link).

Thanks for your help.