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