Skip to content
Add Uploadify support for symfony2
JavaScript PHP
Find file
New pull request
Latest commit 436180a @ruian Merge pull request #11 from umpirsky/form-fixes
Made form compatible with Symfony master.


Build Status

/Warning\ i made a new version of this bundle you can still use the old one by using the tag v1.0



Step 1) Get the bundle

Go into your deps file add these lines:


Launch install php bin/vendors install

Step 2) Register the namespaces

Go into your app/autoload.php file and register this new namespace:

// app/autoload.php
    // ...
    'Ruian' => __DIR__.'/../vendor/bundles',
    // ...

Step 3) Register the bundle

Go into your app/AppKernel.php, and register it in your Kernel:

// app/AppKernel.php

public function registerBundles()
    $bundles = array(
        // ...
        new Ruian\UploadifyBundle\RuianUploadifyBundle(),
    // ...

How to


Go into your app/config.yml and choose a secret key to encrypt your Session_id

    token: "Th1sIs@S3cret!"

Imagine you have a user model like this

namespace Acme\DemoBundle\Model;

class Picture
    protected $data;

    public function __construct($data = null)
        if (null !== $data) {
            $this->data = $date;

     * @return string
    public function getData()
        return $this->data;

     * @param $data
     * @return void
    public function setData($data)
        $this->data = $data;

Create a form associate

namespace Acme\DemoBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class PictureType extends AbstractType
    public function buildForm(FormBuilder $builder, array $options)
            ->add('data', 'hidden')
            ->add('picture_uploadify', 'uploadify_resource', array(
                'data' => array(
                    'folder'  => '/uploads/files/',
                    'preview' => 'picture_preview',
                    'path'    => 'AcmeDemoBundle_upload',
                    'copy'    => $this->getName() . '_' . 'data'
                'property_path' => false

    public function getName()
        return "picture_type";

    // some code ...


// The folder where you to save your files
'folder'  => '/uploads/files/'

// If you want to have a preview of your download give an ID element from your DOM
'preview' => 'picture_preview'

// give a route to uploadify to upload your file
'path'    => 'RuianUploadifyBundle_upload'

// Referrer the property who is linked to uploadify
'copy'    => $this->getName() . '_' . 'picture'

Now we have all elements let's go with our controller and view


    pattern:  /new
    defaults: { _controller: AcmeDemoBundle:Demo:new }

    pattern:  /upload
    defaults: { _controller: AcmeDemoBundle:Demo:upload }


namespace Acme\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Acme\DemoBundle\Model\Picture;
use Acme\DemoBundle\Form\Type\PictureType;
use Ruian\UploadifyBundle\Model\Resource;

class DemoController extends Controller
    // some code ...

    public function newAction()
        $form = $this->createForm(new PictureType(), new Picture());

        // some code ...

        return $this->render('AcmeDemoBundle:Demo:new.html.twig', array(
            'form' => $form->createView()

    // some code ...

    public function uploadAction()
        $request = $this->get('request');

        $entity = new Resource($this->container->getParameter('kernel.root_dir') . '/../web/');



        $response = new Response(json_encode($entity->toArray()));
        $response->headers->set('Content-Type', 'application/json; charset=UTF-8');
        return $response;


<!DOCTYPE html>
    <link rel="stylesheet" type="text/css" href="{{ asset('bundles/ruianuploadify/css/uploadify.css') }}">
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src="{{ asset('bundles/ruianuploadify/js/swfobject.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/ruianuploadify/js/uploadify.js') }}"></script>
    <!-- some code ... -->
    <form method="post" action="{{ path('AcmeDemoBundle_new') }}">
        {% form_theme form 'RuianUploadifyBundle:Form:fields.html.twig' %}
        {{ form_widget(form) }}
        <input type="submit" value="save"/>
    <!-- some code ... -->

Install assets

php5 app/console assets:install web/

If you prefer you can choose to not use the form theme i give to you but you will need to write all the js :-) Or you can just override it into your bundle RuianUploadifyBundle/Resources/views/Form/fields.html.twig


  • add validator for myme type
Something went wrong with that request. Please try again.