Download the PHP package craigh/file-uploader without Composer

On this page you can find all versions of the php package craigh/file-uploader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package file-uploader

FileUploader

Build Status

An easily configurable file uploader for uploading files via a web form

Features

Installing

The easiest way to install is via Composer:

composer require craigh/file-uploader

or you can add craigh/file-uploader to your composer.json file and run composer update

Note: The FileUploader requires symfony/HttpFoundation, so if you are not using composer you will need to make sure you have this library in your include path.

Usage

The FileUploader requires a Symfony\Component\HttpFoundation\File\UploadedFile object. You can easily retrieve an instance by passing the $_FILES['Your_field_name'] variable into the getUploadedFile() method on the Humps\FileUploader\File class:

$file = Humps\FileUploader\File::getUploadedFile($_FILES['file']);

This can then be passed in to the FileUploader:

$uploader = new Humps\FileUploader\FileUploader($file);

You can then upload the file as follows:

$uploader->upload();

Options

uploadDir(string)

Sets the upload path. It will also append any required '/' if it is not set, so both 'path/to/dir' and 'path/to/dir/' will work (defaults to current directory)

$uploader->uploadDir('path/to/dir');

overwrite(boolean)

Set to true to allow overwriting of files with the same name (default: false)

$uploader->overwrite(true);

allowedMimeTypes(array)

Pass in an array of allowed mime types, everything else will be blocked. When empty all file types will be allowed unless explicitly blocked.

$uploader->allowedMimeTypes(['image/jpeg,'image/png', 'image/gif']);

blockedMimeTypes(array)

You can also block file types if you prefer. Pass in an array of mime types you want to block

$uploader->blockedMimeTypes(['application/x-msdownload']);

maxFileSize($size, $unit)

The maximum file size you want to allow, expects size to be a number and unit to be either:

$uploader->maxFileSize(5, 'MB');

You can also use the words BYTE, BYTES, KILOBYTE, KILOBYTES, MEGABYTE or MEGABYTES if you prefer:

$uploader->maxFileSize(1, 'MEGABYTE');

createDirs(bool)

If set to true this will recursively create any specified directories if they do not exist (default: false)

$uploader->createDirs(true);

makeFilenameUnique(bool)

If set to true this will make the filename unique by appending a _{number} to the end.

$uploader->makeFilenameUnique(true);

filename(string)

By default the filename will be a sanitised version of the uploaded filename. Use this method if you want to set your own filename.

$uploader->filename('myFile.txt');

Note: When using this method the filename will not be sanatised, if you want to sanatise the filename you can use the sanitizeFilename() method.

sanitizeFilename()

Sanitises the given filename by removing any non alpha numeric characters and replacing any spaces with an underscore. You will only need to call this if you want to set your own filenames using the filename() method, otherwise this method is called automatically. You should also be aware that this call will need to be made after you set your filename:

upload()

Uploads the file and returns the upload path.

$uploadPath = $uploader->upload();

upload() is an alias of move(), so you can also use the move() method if you feel it's wording is more appropriate:

$uploadPath = $uploader->move();

Chaining

All methods above can be applied in a chain for a clean syntax:

or even

Config by Extending the FileUploader Class

For a cleaner way to configure you uploads you can extend the FileUploader class which will give you access to the protected variables, e.g.:

This can then be used as follows:

The following variables are protected and so can be set by child classes:

A note on the examples

If you want to run the examples then you will need to change the include path to point to your autoloader or include the FileUploader classes manually.


All versions of file-uploader with dependencies

PHP Build Version
Package Version
Requires symfony/http-foundation Version ~3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package craigh/file-uploader contains the following files

Loading the files please wait ....