Jump to:

10845 Posts in 2516 Topics by 1792 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: 2453 Views
  • tbarho
    Avatar
    Community Member
    41 Posts

    SWFUpload Issue Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: SWFUpload Issue Link to this post

    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?

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    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!

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

    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

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: SWFUpload Issue Link to this post

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

  • tbarho
    Avatar
    Community Member
    41 Posts

    Re: SWFUpload Issue Link to this post

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

    Thanks!

  • UncleCheese
    Avatar
    4085 Posts

    Re: SWFUpload Issue Link to this post

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

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