2017 © Pedro Peláez
 

library php-upload

File uploader

image

sokil/php-upload

File uploader

  • Monday, March 12, 2018
  • by sokil
  • Repository
  • 2 Watchers
  • 2 Stars
  • 141 Installations
  • PHP
  • 2 Dependents
  • 1 Suggesters
  • 1 Forks
  • 3 Open issues
  • 15 Versions
  • 4 % Grown

The README.md

PHP Uploader

Latest Stable Version Build Status Coverage Status, (*1)

Installation

You can install library through Composer:, (*2)

{
    "require": {
        "sokil/php-upload": "dev-master"
    }
}
  • https://github.com/sokil/upload.js - frontend component. Implements uploading wile without reloading page with upload progress
  • https://github.com/sokil/php-upload-sandbox - Sandbox to test backend (this library) and frontend (https://github.com/sokil/upload.js). To start testing just clone repo and start server.
  • https://github.com/sokil/FileStorageBundle - Symfony bundle

Quick start

First create HTML:, (*3)

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

Then add PHP code to upload action to upload file to local system:, (*4)

<?php

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

Also library supports Gaufrette filesistems. Read about Gaufrette at https://github.com/KnpLabs/Gaufrette. Read abount configuring Gaufrette filesystems in Symfony at https://github.com/KnpLabs/KnpGaufretteBundle., (*5)

To upload file into Gaufrette Filesystem:, (*6)

<?php

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

$uploader = new \Sokil\Upload\Handler([
    'fieldName' => 'attachment',
]);
$uploader->move($filesystem);

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., (*7)

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., (*8)

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

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+., (*10)

Nginx must be compiled with this modules: * Upload module: https://github.com/vkholodkov/nginx-upload-module, (*11)

--add-module=/path/to/nginx-upload-module
  • Upload progress module: https://github.com/masterzen/nginx-upload-progress-module
--add-module=/path/to/nginx-upload-progress-module

Example of nginx configuration to handle upload and progress:, (*12)

upload_progress upload 5m;

server
{
    location @php
    {
        fastcgi_pass 127.0.0.1:9000;
        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_field_name.name "$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 http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_in_file_only, (*13)

Currently not supported, (*14)

The Versions

12/03 2018

dev-master

9999999-dev

File uploader

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

07/07 2017

0.6.8

0.6.8.0

File uploader

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

07/07 2017

0.6.7

0.6.7.0

File uploader

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

09/06 2017

0.6.5

0.6.5.0

File uploader

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

05/03 2016

0.6.4

0.6.4.0

File uploader

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

04/03 2016

0.6.3

0.6.3.0

File uploader

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

28/02 2016

0.6.2

0.6.2.0

File uploader

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

26/02 2016

0.6.1

0.6.1.0

File uploader

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

12/01 2016

0.6

0.6.0.0

File uploader

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

24/08 2014

0.5.3

0.5.3.0

File uploader

  Sources   Download

MIT

by Dmytro Sokil

31/07 2014

0.5.1

0.5.1.0

File uploader

  Sources   Download

MIT

by Dmytro Sokil

28/06 2014

0.5

0.5.0.0

File uploader

  Sources   Download

MIT

by Avatar sokil

28/06 2014

0.4

0.4.0.0

File uploader

  Sources   Download

MIT

by Avatar sokil

24/06 2014

0.3

0.3.0.0

File uploader

  Sources   Download

MIT

by Avatar sokil

03/02 2014

0.2

0.2.0.0

File uploader

  Sources   Download

MIT

by Avatar sokil