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.

All other Modules /

Discuss all other Modules here.

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

SWFUpload Issue


Reply


25 Posts   2733 Views

Avatar
tbarho

Community Member, 41 Posts

15 March 2010 at 3:23pm

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!

Avatar
tbarho

Community Member, 41 Posts

15 March 2010 at 3:24pm

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

Avatar
tbarho

Community Member, 41 Posts

15 March 2010 at 3:45pm

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

Avatar
UncleCheese

Forum Moderator, 4092 Posts

15 March 2010 at 4:10pm

On the frontend?

Avatar
tbarho

Community Member, 41 Posts

15 March 2010 at 5:29pm

Yes, on the frontend. Very confused :)

Avatar
UncleCheese

Forum Moderator, 4092 Posts

16 March 2010 at 2:56am

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();
}
}
}

Avatar
tbarho

Community Member, 41 Posts

16 March 2010 at 5:04am

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.

Avatar
tbarho

Community Member, 41 Posts

16 March 2010 at 5:09am

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.