tps / dnd-file-upload-bundle
The bundle offers a twig filter for creating drag-and-drop file-uploads in your symfony2 app
Installs: 80
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.2
- doctrine/doctrine-bundle: 1.3.*@dev
- doctrine/orm: 2.5.*@dev
- psr/log: 1.0.0
- sensio/framework-extra-bundle: *
- symfony/filesystem: >=2.0.16,~2.0
- symfony/finder: >=2.0.16,~2.0
- symfony/framework-bundle: >=2.0.16,~2.0
- symfony/twig-bundle: *
- twig/twig: >=1.0,<2.0-dev
Requires (Dev)
- phpunit/phpunit: 4.5.*@dev
- satooshi/php-coveralls: 0.7.*@dev
- symfony/browser-kit: *
- symfony/yaml: >=2.0.16,~2.0
This package is auto-updated.
Last update: 2025-03-29 00:56:51 UTC
README
Drag-And-Drop File-Upload Bundle
A drag-and-drop file-upload bundle for symfony2
Installation
Add the following line to your composer.json:
require: "tps/dnd-file-upload-bundle": "dev-master"
Update your dependencies and activate the bundle in the kernel:
//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:
app/console doctrine:schema:update --force
Enable routing
# 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:
<script src="http://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
Loading assets
Using assetic:
{% 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:
{% block javascripts %} {{ parent() }} <script type="text/javascript" src="{{ asset('bundles/dndfileupload/js/class.FileUploader.js') }}"></script> <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):
{# Acme\DemoBundle\Resources\views\index.html.twig #} {% block body %} {{ DndFileUploadContainer('file-upload-container') }} {% endblock %}
To Do
- add JS tests