sfWidgetFormInputSWFUploadPlugin - 0.9.10

Plugin for decorating a file input widget with SWFUpload javascript.

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

sfWidgetFormInputSWFUploadPlugin

sfWidgetFormInputSWFUploadPlugin decorates a file input widget with queued uploading capabilities, provided by SWFUpload (www.swfupload.org).

This plugin is now an required dependancy of sfFilebasePlugin. See at its sample project to see it in action.

Instructions:

Use the widget like an ordinary file upload widget and configure it by passing custom options to its options array.

In custom form you'd to probably manually include the widgets assets (javascripts and stylesheets). Do so by using $myform->getJavascripts() and $myform->getStylesheets().

Please refer to the source file (plugins/sfWidgetFormInputSWFUploadPlugin/lib/widget/sfWidgetFormInputSWFUPload.php) and study the possible widget's options.

Note that the widget uses flash to perform the file upload. That means that the form that wraps the widget will never be submitted by your webbrowser. You may simulate a form submission by setting the option "send_serialized_values". This forces the upload widget to serialize all form values and to send them as additional parameters towards your upload service. This may not be the required behaviour because the serialized data will be send within each server request, which means each file beeing uploaded.

Example:

lib/form/TestForm.php:

class TestForm extends sfForm
{
  public function configure()
  {
    $this->setWidgets(array(
      'upload' => new sfWidgetFormInputSWFUpload()
    ));

    $this->setValidators(array(
      'upload' => new sfValidatorFile()
    ));
  }
}

apps/frontend/modules/default/actions/actions.class.php:

class defaultActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->form = new TestForm();
    if($request->isMethod('put'))
    {
      // VALIDATE THE FORM, DO SOMETHING WITH THE FILES,  ...
      // ..
      // ..

      // UNSET THE RESPONSE
      $this->setLayout(false);
      return sfView::NONE;
    }
  }
}

apps/frontend/modules/default/templates/indexSuccess.php:

<form method="post" enctype="multipart/form-data" accept-charset="utf-8">
  <p>
    <?php use_stylesheets_for_form($form)?>
    <?php use_javascripts_for_form($form)?>
    <?php echo $form?>
    <input type="hidden" name="sf_method" value="put" />
  </p>
</form>

Feel free to override the css to fit your own applications look and feel.

Installation

(Install instructions taken from README in sfThumbnailPlugin, (c) Fabien Potencier)

To install the plugin for a symfony project, the usual process is to use the symfony command line.

With symfony 1.1/1.2/1.3/1.4, use:

$ symfony plugin:install sfWidgetFormInputSWFUploadPlugin

Alternatively, if you don't have PEAR installed, you can download the latest package attached to this plugin's wiki page and extract it under your project's plugins/ directory.

Clear the cache to enable the autoloading to find the new classes:

$ php symfony cc

Publish the plugins assets

$ php symfony plugin:publish-assets

You're done.

Credits

The guys managing and devolping the SWFUpload flash movie as well as its javascript api should be mentioned here. Lern more at http://swfupload.org