File uploader

0.7.0 2019-12-02 21:43 UTC

This package is auto-updated.

Last update: 2024-05-29 02:35:33 UTC


Latest Stable Version Build Status Coverage Status


You can install library through Composer:

    "require": {
        "sokil/php-upload": "dev-master"

Related packages

Quick start

First create HTML:

    <input type="file" name="attachment" />

Then add PHP code to upload action to upload file to local system:


$uploader = new \Sokil\Upload\Handler([
    'fieldName' => 'attachment',
$uploader->moveLocal(__DIR__ . '/uploads/');

Also library supports Gaufrette filesistems. Read about Gaufrette at Read abount configuring Gaufrette filesystems in Symfony at

To upload file into Gaufrette Filesystem:


$filesystem = new \Gaufrette\Filesystem(new \Gaufrette\Adapter\Local(
    __DIR__ . '/attachments/'

$uploader = new \Sokil\Upload\Handler([
    'fieldName' => 'attachment',

Upload transports

Stream upload

Nginx upload

Multipart Form Data Transport

Nginx configuration

During standard upload file is moved to php's temp dir, and then moved to target destination using move_uploaded_file. If this dirs on different physical drives, some time will be spend to move file physically between devices.

There is another reason when nginx + php-fpm stack used. During upload nginx stored file to its own temp dir. After passing control to php-fpm, nginx moves cached file to php's temp dir, and than php moves file to destination using move_uploaded_file. So file copied three times, and maybe on different physical devices.

This method moves file directly to configured drive, so in php code only rename of file required.

Using upload_module and upload_progress_module (nginx < 1.3.9)

This method is deprecated due to compilation errors of upload_module on nginx versions 1.3.9+.

Nginx must be compiled with this modules:


Example of nginx configuration to handle upload and progress:

upload_progress upload 5m;

    location @php
        fastcgi_param SCRIPT_FILENAME $document_root/app.php;
        include /etc/nginx/fastcgi_params;

    location /upload
        upload_pass @php;
        upload_store %PATH_TO_STORAGE_DIRECTORY%;
        upload_pass_args on;
        upload_max_file_size 0;

        upload_set_form_field $ "$upload_file_name";
        upload_set_form_field $upload_field_name.type "$upload_content_type";
        upload_set_form_field $upload_field_name.tmp_name "$upload_tmp_path";

        upload_aggregate_form_field $upload_field_name.size "$upload_file_size";

        track_uploads upload 5s;

    location /progress
        report_uploads upload;


Using client_body_in_file_only directive

See more info at

Currently not supported