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


Go to End
Reply

25 Posts   2663 Views

Avatar
tbarho

12 March 2010 at 7:01pm Community Member, 41 Posts

I'm having an issue with SWFUpload, and was wondering if anyone else had had this issue. Basically, I have:

class Project_Controller extends Page_Controller
{
function MessageForm($id = 0)
{
$params = $this->getURLParams();

if ($params['ID']) {
$id = (int)$params['ID'];
}

return new MessageForm($this, 'MessageForm', $id);

}
public function handleswfupload()
{
if(isset($_FILES['swfupload_file']) && is_array($_FILES['swfupload_file']))
{

echo Folder::findOrMake('ProjectDocs')->addUploadToFolder($_FILES['swfupload_file']);
} else {
echo ' ';
}
}
}

which is a custom controller returning a "MessageForm". MessageForm looks like this:

class MessageForm extends Form
{
function __construct($controller, $name, $id = 0)
{
SWFUploadConfig::addFileTypes(array(
'pdf', 'doc', 'jpg', 'png'
));

$fields = singleton('Message')->getFrontEndFields();

$fields->push(new HiddenField('ProjectId', 'ProjectId', $id));
$fields->push(new SWFUploadField(
$name,
'Files',
'Upload Files',
array(
'file_upload_limit' => '1',
'debug' => 'true'
)
));

$validators = new RequiredFields('Body');

$actions = new FieldSet(new FormAction('submit', 'Save Message'));

parent::__construct($controller, $name, $fields, $actions, $validators);
}

function submit($data, $form)
{

$projectId = (int)$data['ProjectId'];

if (0 != $projectId) {
$project = DataObject::get_by_id('Project', $projectId);
} else {
$project = new Project();
$project->Title = 'New Project by ' . Member::currentUser()->getName() . ' at ' . date('d/m/Y H:i:s');
$project->ClientID = Member::currentUserID();
$project->ClientView = true;
$project->AdminView = false;
$project->write();

}

// add the message to the project
$message = new Message();
$message->Body = $data['Body'];
$message->ProjectID = $project->ID;
$message->ClientID = Member::currentUserID();

if (isset($_POST['uploaded_files']) && is_array($_POST['uploaded_files'])) {
foreach ($_POST['uploaded_files'] as $id) {
$file = DataObject::get_by_id('File', $id);
$message->Files->push($file);
}
}

$message->write();
Director::redirectBack();
}

}

All that happens is my SWFUploadField just sits on Uploading. . . and does nothing.

The debug from SWFUpload looks like this:

SWF DEBUG: ----- SWF DEBUG OUTPUT ----
SWF DEBUG: Build Number: SWFUPLOAD 2.2.0 Alpha 2008-10-17
SWF DEBUG: movieName: SWFUpload_0
SWF DEBUG: Upload URL: http://silverstripe/Project_Controller/handleswfupload
SWF DEBUG: File Types String: *.pdf;*.PDF;*.doc;*.DOC;*.jpg;*.JPG;*.png;*.PNG;
SWF DEBUG: Parsed File Types: pdf,pdf,doc,doc,jpg,jpg,png,png,
SWF DEBUG: File Types Description: (*.pdf;*.PDF;*.doc;*.DOC;*.jpg;*.JPG;*.png;*.PNG;)
SWF DEBUG: File Size Limit: 33554432 bytes
SWF DEBUG: File Upload Limit: 1
SWF DEBUG: File Queue Limit: 1
SWF DEBUG: Post Params:
SWF DEBUG: ----- END SWF DEBUG OUTPUT ----
SWF DEBUG:
SWF DEBUG: Event: fileDialogStart : Browsing files. Multi Select. Allowed file types: *.pdf;*.PDF;*.doc;*.DOC;*.jpg;*.JPG;*.png;*.PNG;
SWF DEBUG: Select Handler: Received the files selected from the dialog. Processing the file list...
SWF DEBUG: Event: fileQueued : File ID: SWFUpload_0_0
SWF DEBUG: Event: fileDialogComplete : Finished processing selected files. Files selected: 1. Files Queued: 1
SWF DEBUG: StartUpload: First file in queue
SWF DEBUG: Event: uploadStart : File ID: SWFUpload_0_0
SWF DEBUG: ReturnUploadStart(): File accepted by startUpload event and readied for upload. Starting upload to http://silverstripe/Project_Controller/handleswfupload for File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress (OPEN): File ID: SWFUpload_0_0

What I would like to be able to do is upload multiple files per message from the Front End MessageForm, that are linked to a Message DataObject, which has a

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

Can anyone help out there? UncleCheese? Willr? Thanks so much!

Ty

Avatar
UncleCheese

13 March 2010 at 3:16am 4085 Posts

In newer versions of SWFUpload, you don't need to write a controller action like that. It will fall back on SWFUploadControls::handleswfupload() by default. I'm actually kind of surprised that it's using Project_Controller for your upload URL because it doesn't appear to me that you've set that anywhere. Do you have a SWFUploadControls class?

Avatar
tbarho

13 March 2010 at 5:18am Community Member, 41 Posts

I don't have that set anywhere, I just read that by default it looks for that. I'll grab a new version and see if that helps. Any help on adding files to a dataobject? Or does SilverStripe just handle that automatically?

I was trying to use something like:

class SomeDataObject extends DataObject
{
static $has_many = array('Files' => 'File');
}

Then in the controller, in my form action:

function submit($data, $form)
{
//...

$someDataObject = new SomeDataObject();

if (isset($_POST['uploaded_files']) && is_array($_POST['uploaded_files'])) {
foreach ($_POST['uploaded_files'] as $id) {
$file = DataObject::get_by_id('File', $id);
$someDataObject->Files->push($file);
}
}
$someDataObject->write();
}

Is that right? Or is there a better way to do that?

Thanks!

Avatar
tbarho

13 March 2010 at 5:26am Community Member, 41 Posts

Oh, and is there a new SWFUpload module for SS? Or do I have to manually integrate the newer versions of SWFUpload myself? I can't seem to find a download for SWFUpload SS.

Thanks!

Ty

Avatar
tbarho

13 March 2010 at 5:40am Community Member, 41 Posts

Oh, and no I dont have a SWFUploadControls class. Where would I put that, and what would it do?

Avatar
UncleCheese

13 March 2010 at 5:47am 4085 Posts

I would just update to the latest version. That's been in the core for a while.

Avatar
tbarho

13 March 2010 at 5:52am Community Member, 41 Posts

To the latest version of SS or to SWFUpload Field? If it's the latter, do I do it off your site?

Thanks!

Avatar
UncleCheese

13 March 2010 at 6:25am 4085 Posts

I think the modules section on Silverstripe is current, but the best way is through svn..

svn co http://carlinowebdesign.svn.beanstalkapp.com/modules/trunk/swfupload

Go to Top