10376 Posts in 2191 Topics by 1708 members
| Go to End | Next > | |
| Author | Topic: | 2089 Views |
-
Re: SWFUpload Issue

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!
-
Re: SWFUpload Issue

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
how would I add the files to it? I've been trying to usestatic $has_many = array('Files' => 'File')
, but that doesn't seem to work . . .$myDataObject->push($myFile)
-
Re: SWFUpload Issue

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();
}
}
} -
Re: SWFUpload Issue

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
underneath where the variable $class is determined in handleswfupload() in SWFUploadControls.die($class);
-
Re: SWFUpload Issue

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.
| 2089 Views | ||
| Go to Top | Next > |

