Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Cant get SWFUploadField to work on front end

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: 1510 Views
  • bonesbrigade
    Avatar
    Community Member
    10 Posts

    Cant get SWFUploadField to work on front end Link to this post

    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
    /profiles/code/ProfilePage.php

       
    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>
       </ul>";
       $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->setTemplate('ProfilePage_gallery');
       }

       // 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);
             $file->write();
             echo $file->ID;
          }
          else{echo ' ';}

    Where am I going wrong?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Cant get SWFUploadField to work on front end Link to this post

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

  • bonesbrigade
    Avatar
    Community Member
    10 Posts

    Re: Cant get SWFUploadField to work on front end Link to this post

    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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Cant get SWFUploadField to work on front end Link to this post

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

  • bonesbrigade
    Avatar
    Community Member
    10 Posts

    Re: Cant get SWFUploadField to work on front end Link to this post

    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.

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