Download the PHP package vkr/symfony-web-uploader without Composer
On this page you can find all versions of the php package vkr/symfony-web-uploader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package symfony-web-uploader
About
This small library (not a bundle!) simplifies uploading files to an external resource via an API. Since version 1.2, this library depends on Symfony.
This library does not do anything by itself, it is designed to be extended by other bundles or libraries.
Installation
Nothing to install here, really.
Usage
In Symfony projects
First, you need to create a concrete service implementation of class. This service needs to have a single method called that does not accept arguments and by convention should return .
Here are the properties that can be accessed from inside that method:
-
- object acting as a handler for original file
-
- full path to the remote destination folder without trailing slash
-
- the name that will be given for your newly uploaded file - see name changers
If you register this service inside Symfony service container, you will need to install VKRSettingsBundle and add it as an argument to :
Then, you will need to create three settings either as parameters or inside your DB:
-
- an array of MIME types
-
- max size in bytes that can be uploaded
- a setting with arbitrary name with full URL to remote destination folder, with or without trailing slash
See VKRSettingsBundle manual on how settings can be defined.
Here is how you access this service from your controller:
Here checks if the uploaded file exists, has same size and MIME type as the original file and throws exception on error.
If you want to disable checks for size and MIME type, you can call:
Name changers
The second argument to is a name changer object. It defines what name will the new file have. If no name changer is present, the new file will have the same name as the original. Name changers must implement .
Suppose that you want all files to be renamed with current Unix timestamps, in this case your name changer will look like this:
Then in your controller:
You do not need to create a name changer if your file was just uploaded by a client and you want to keep the client filename in this case the default new name will correspond to the client filename, not to the PHP temporary name.
Outside of Symfony
Things are not that different outside of Symfony, however you cannot use VKRSettingsBundle and must pass your settings as an array:
Also, if you are forwarding a file that was just uploaded from a form, you need to initialize it manually:
All versions of symfony-web-uploader with dependencies
symfony/http-foundation Version ~2.8|~3.0
vkr/settings-bundle Version ~1.1