Download the PHP package rossriley/upload without Composer
On this page you can find all versions of the php package rossriley/upload. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rossriley/upload
More information about rossriley/upload
Files in rossriley/upload
Package upload
Short Description Framework agnostic upload library - Forked from siriusphp for PHP 5.3 compatibility
License MIT
Informations about the package upload
Sirius\Upload
Framework agnostic upload handler library.
Features
- Validates files agains usual rules: extension, file size, image size (wdith, height, ratio). It uses Sirius Validation for this purpose.
- Moves valid uploaded files into containers. Containers are usually local folders but you can implement your own or use other filesystem abstractions like Gaufrette or Flysystem.
Elevator pitch
One aggregator to rule them all
Sometimes your form may upload multiple files to the server. To reduce the number of process()
, clear()
and confirm()
calls you can use an "upload handler aggregate"
You can see the aggregator and handlers in action in the tests/web/index.php
How it works
- Uploaded file is validated against the rules. By default the library will check if the upload is valid (ie: no errors during upload)
- The name of the uploaded file is sanitized (keep only letters, numbers and underscore and lowercase the result). You may implement your own sanitization function if you want.
- If overwrite is not allowed, and a file with the same name already exists in the container, the library will prepend the timestamp to the filename.
- Moves the uploaded file to the container. It also create a lock file (filename + '.lock') so that we know the upload is not confirmed
- If something wrong happens in your app and you want to get rid of the uploaded file you can
clear()
the uploaded file which will remove the file and its.lock
file. Only files that have a coresponding.lock
file attached can be cleared - If everything is in order you can
confirm
the upload. This will remove the.lock
file attached to the upload file.
What is "locking"?
Usualy application accept file uploads to store them for future use (product images, people resumes etc). But from the time an uploaded file is moved to its container until the actual data is saved there are things that can go wrong (eg: the database goes down).
For this reason the locking
functionality was implemented. This way, even if you're not able to execute the clear()
method you will be able to look into the container in "spot" the unused files. This feature must be used with care
- If you want to take advantage of this feature you must use
confirm
- If you don't like it, use
$uploadHandler->setAutoconfirm(true)
and all uploaded files will automatically confirmed
Using different containers
If you want to store uploaded files in different locations your containers must implement the Sirius\Upload\Container\ContainerInterface
.
You can easily create upload containers on top of Gaufrette or Flysystem.
Important notes
1. The library makes no assumptions about the "web availability" of the uploaded file.
Most of the times once you have a valid upload the new file will be reachable on the internet. You may upload your files to /var/www/public/images/users/
and have the files accessible at //cdn.domain.com/users/
. It's up to you to make your app work with the result of the upload.
2. You can handle multiple uploads at once if they have the same name
If you upload multiple files with the same name (eg: <input type="file" name="pictures[]">
) but you have to keep in mind that the process()
and getMessages()
methods will return arrays
In this case the library normalizes the $_FILES
array as PHP messes up the upload array.
It is up to you to decide what you want to do when some files fail to upload (eg: keep the valid files and continue or display error messages for the invalid images)