Jump to:

10977 Posts in 2720 Topics by 1815 members

All other Modules

SilverStripe Forums » All other Modules » SWFUpload Issue

Discuss all other Modules here.

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

Page: 1 2 3 4
Go to End
Author Topic: 2610 Views
  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    Ok, I got it to upload, but now I'm getting an alert that says "Server said: 121" or "Server said: 122". I know that's the ID of the file I just uploaded, but I'm not sure how to get past that message an on to the "submit" action that my form is supposed to be running.

    Any ideas?

    Thanks!

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    Oh, I'm stupid. Just turn off the debug mode =)

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    So I think I'm getting it, but I'm just stuck on adding uploaded images to a dataobject. If I have a

    static $has_many = array('Files' => 'File')

    how would I add the files to it? I've been trying to use

    $myDataObject->push($myFile)

    , but that doesn't seem to work . . .

  • UncleCheese
    Avatar
    4085 Posts

    Re: SWFUpload Issue Link to this post

    On the frontend?

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    Yes, on the frontend. Very confused

  • UncleCheese
    Avatar
    4085 Posts

    Re: SWFUpload Issue Link to this post

    It's super easy. First things first, you need to either decorate your File object or use a subclass, because the File object is going to need a foreign key to tie it back to its holder object.

    class MyFile extends File
    {
    static $has_one = array (
    'SomeDataObject' => 'SomeDataObject'
    );
    }

    Somewhere in your form function, set:

    SWFUploadControls::$file_class = "MyFile";

    If that throws an error, update SWFUpload. That property was added recently. If you're using a decorator, you don't need that step because the value defaults to "File."

    Then in the handler for your form post, you have the array $data['uploaded_files'], which is a list of all the file IDs that were uploaded through SWFUpload.

    if(isset($data['uploaded_files']) && is_array($data['uploaded_files'])) {
    foreach($data['uploaded_files'] as $id) {
    if($file = DataObject::get_by_id("MyFile", $id)) {
    $file->SomeDataObjectID = $someDataObject->ID;
    $file->write();
    }
    }
    }

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    When you say "in for your form function" do you mean in the form constructor or in the handleswfupload() method? Cause I added that, but it doesnt seem to be doing anything. I'm subclassing Form for a custom form, and in the __construct method I've added:

    SWFUploadControls::$file_class = "MyFile";

    but nothing happens, and the file is still saved as a "File" class. I checked this by adding

    die($class);

    underneath where the variable $class is determined in handleswfupload() in SWFUploadControls.

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    I also checked this with

    SWFUploadConfig::set_default_upload_dir("SomeNewDirectory");

    It seems that if you're subclassing form and pushing a new SWFUploadField to your form in the __construct() method, some of the config options get set, and some don't. Using

    SWFUploadConfig::$debug = "true";

    Works as expected, but the other two I've mentioned in the last 2 posts don't seem to do anything.

    2610 Views
Page: 1 2 3 4
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.