2017 © Pedro Peláez
 

symfony-bundle dnd-file-upload-bundle

The bundle offers a twig filter for creating drag-and-drop file-uploads in your symfony2 app

image

tps/dnd-file-upload-bundle

The bundle offers a twig filter for creating drag-and-drop file-uploads in your symfony2 app

  • Friday, January 2, 2015
  • by leberknecht
  • Repository
  • 0 Watchers
  • 1 Stars
  • 57 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 8 % Grown

The README.md

Build Status Coverage Status, (*1)

Drag-And-Drop File-Upload Bundle

A drag-and-drop file-upload bundle for symfony2, (*2)

Installation

Add the following line to your composer.json:, (*3)

require: "tps/dnd-file-upload-bundle": "dev-master"

Update your dependencies and activate the bundle in the kernel:, (*4)

//app/AppKernel.php
$bundles = array(
    [...]
    new \tps\DndFileUploadBundle\DndFileUploadBundle()
)

Usage

App-Config

#app/Resources/config/config.yml
dnd_file_upload:
    twig:
        css_class:        dnd-file-upload-container
    upload_directory:     uploads
    allowed_mimetypes:    [ '*' ]
    persist_entity:       true
    entity_class:         Acme\DemoBundle\Entity\MyUploadedFile

Entity

namespace Acme\DemoBundle\Entity;

use tps\DndFileUploadBundle\Entity\File as UploadedFile;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="file_uploads") //remove this if you dont want to persist
 * @ORM\Entity()
 */
class MyUploadedFile extends UploadedFile
{
     /**
      * @var integer $id
      *
      * @ORM\Column(name="id", type="integer")
      * @ORM\Id
      * @ORM\GeneratedValue(strategy="AUTO")
      */
     protected $id;
}

If you want the uploaded files to be persisted in your database, run:, (*5)

app/console doctrine:schema:update --force
````

### Enable routing
```yaml
# app/Resources/config/routing.yml
dnd_file_upload_routing:
    resource: "@DndFileUploadBundle/Resources/config/routing.yml"

View

If you dont have jQuery included allready, do so before you include bundle snippets:, (*6)

<script src="http://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>

Loading assets

Using assetic:, (*7)

{% javascripts
    '@DndFileUploadBundle/Resources/public/js/class.FileUploader.js'
    '@DndFileUploadBundle/Resources/public/js/class.UploadThreadWrapper.js'
    '@DndFileUploadBundle/Resources/public/js/bind.js'
%}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

Using "normal" assets:, (*8)


{% block javascripts %} {{ parent() }} <script type="text/javascript" src="{{ asset('bundles/dndfileupload/js/class.UploadThreadWrapper.js') }}"></script> <script type="text/javascript" src="{{ asset('bundles/dndfileupload/js/bind.js') }}"></script> {% endblock %} {% block stylesheets %} {{ parent() }} <link href="{{ asset('bundles/dndfileupload/css/default.css') }}" type="text/css" rel="stylesheet" media="screen" /> {% endblock %}

create upload-container

Finally, create the upload-container (the "file-upload-container" parameter is the id of the container in the DOM, use it for styling):, (*9)

{# Acme\DemoBundle\Resources\views\index.html.twig #}
{% block body %}
    {{ DndFileUploadContainer('file-upload-container') }}
{% endblock %}

To Do

  • add JS tests

The Versions