PHPackages                             tamedevelopers/file - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. tamedevelopers/file

ActiveLibrary[File &amp; Storage](/categories/file-storage)

tamedevelopers/file
===================

PHP Library for uploading files

3.0.6(2mo ago)282MITPHPPHP &gt;=8.0CI failing

Since Oct 4Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/tamedevelopers/file)[ Packagist](https://packagist.org/packages/tamedevelopers/file)[ RSS](/packages/tamedevelopers-file/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (30)Used By (0)

File Upload
===========

[](#file-upload)

[![Total Downloads](https://camo.githubusercontent.com/8c4cf71d835b021323f54ca18b5b6a80c6a8f96b6a5ac43e3aa5009a3aa76854/68747470733a2f2f706f7365722e707567782e6f72672f74616d65646576656c6f706572732f66696c652f646f776e6c6f616473)](https://packagist.org/packages/tamedevelopers/file)[![Latest Stable Version](https://camo.githubusercontent.com/469c3a0a8e935c97717be922a4f0c62e3c46e41a8481b48c2708ad4d45184819/68747470733a2f2f706f7365722e707567782e6f72672f74616d65646576656c6f706572732f66696c652f76657273696f6e)](https://packagist.org/packages/tamedevelopers/file)[![License](https://camo.githubusercontent.com/88891f3e1bec1ea2574821785f101cf93b11b90533aa6541c3eb7e91fd885009/68747470733a2f2f706f7365722e707567782e6f72672f74616d65646576656c6f706572732f66696c652f6c6963656e7365)](https://packagist.org/packages/tamedevelopers/file)[![Build Status](https://github.com/tamedevelopers/file/actions/workflows/php.yml/badge.svg)](https://github.com/tamedevelopers/file/actions)[![Code Coverage](https://camo.githubusercontent.com/9538517072e8370b1ae157a2a6816e76e3c795943a613690075aca6a50f6775a/68747470733a2f2f636f6465636f762e696f2f6769746875622f74616d65646576656c6f706572732f66696c652f67726170682f62616467652e7376673f746f6b656e3d4747573130335244374b)](https://codecov.io/github/tamedevelopers/file)

Documentation
-------------

[](#documentation)

- [Requirements](#requirements)
- [Installation](#installation)
- [Instantiate](#instantiate)
- [Amazon Aws S3](#amazon-aws-s3)
- [Global Config](#global-config)
- [INPUT HTML STRUCTURE](#input-html-structure)
- [Response Data](#response-data)
    - [Get Message](#get-message)
    - [Get Status](#get-status)
    - [Get Class](#get-class)
    - [First](#first)
    - [Get](#get)
    - [Form](#form)
    - [Unlink](#unlink)
- [Usage](#usage)
    - [Name](#name)
    - [Driver](#driver)
    - [BaseDir](#baseDir)
    - [Generate](#generate)
    - [Folder](#folder)
    - [Filter](#filter)
    - [filterExtention](#filterExtention)
    - [Structure](#structure)
    - [Size](#size)
    - [Limit](#limit)
    - [Mime](#mime)
    - [Width](#width)
    - [Height](#height)
    - [Validate](#validate)
    - [Save](#save)
    - [Resize](#resize)
    - [WaterMark](#watermark)
    - [Compress](#compress)
    - [Get External Image Size](#get-external-image-size)
    - [Get Uploaded Image Size](#get-uploaded-image-size)
    - [Get Mime Type](#get-mime-type)
    - [Not Empty](#not-empty)
    - [Is Empty](#is-empty)
    - [Has Error](#has-error)
    - [Is Completed](#is-completed)
    - [Mime Types](#mime-types)
- [Useful links](#useful-links)

Requirements
------------

[](#requirements)

- `>= php 8.0+`

Installation
------------

[](#installation)

Prior to installing `support package` get the [Composer](https://getcomposer.org) dependency manager for PHP because it'll simplify installation.

```
composer require tamedevelopers/file

```

Instantiate
-----------

[](#instantiate)

**Step 1** — Composer `Instantiate class using`:

```
require_once __DIR__ . '/vendor/autoload.php';

use Tamedevelopers\File\File;

$file = new File();

```

- **Example 2**

```
require_once __DIR__ . '/vendor/autoload.php';

$file = new Tamedevelopers\File\File();

```

- or -- `Helpers Function`

```
$file = TameFile();

```

Amazon Aws S3
-------------

[](#amazon-aws-s3)

- To use s3 first require `composer require aws/aws-sdk-php`
- By default Aws load entire SDK we won't be needing
    - Copy the below code into your root `composer.json` and then run `composer update` in terminal.

```
"scripts": {
    "pre-autoload-dump": "Aws\\Script\\Composer\\Composer::removeUnusedServices"
},
"extra": {
    "aws/aws-sdk-php": [
        "Ec2",
        "CloudWatch"
    ]
}

```

Global Config
-------------

[](#global-config)

- Configure The Global Config, so you don't have to always include default settings
    - Define as `named argument`

KeyTypesDescriptionmessageAssoc `array`Create all error messagesconfigAssoc `array`Create all needed config dataclassAssoc `array`Create error and success class```
config_file(
    message: [
        '401'   => 'Select file to upload',
        '402'   => 'File upload is greater than allowed size of:',
        '403'   => 'Maximum file upload exceeded. Limit is:',
        '404'   => 'Uploaded file format not allowed. Allowed formats:',
        '405'   => 'Image dimension allowed is:',
        '405x'  => 'Image dimension should be greater than or equal to:',
        '200'   => 'File uploaded successfully:',
        'kb'    => 'kb',
        'mb'    => 'mb',
        'gb'    => 'gb',
        'and'   => 'and',
        'width' => 'width',
        'height'=> 'height',
        'files' => 'files',
        'file'  => 'file',
    ],
    config: [
        'limit'         => 1,
        'mime'          => 'image', // video|audio|file|image|zip|pdf|xls|doc|general_image|general_media|general_file
        'size'          => '2mb',
        'baseDir'       => 'public',
        'driver'        => 'local',
        'structure'     => 'default', // default|year|month|day
        'generate'      => true, // will always generate a unique() name for each uploaded file
    ],
    class: [
        'error'     => 'bg-danger',
        'success'   => 'bg-success',
    ]
);

```

- or -- using file class method `Global Config`

```
(new File)->globalConfig(
    message: [],
    config: [],
    class: []
);

```

### INPUT HTML STRUCTURE

[](#input-html-structure)

```

```

- or -- `For Multiple Data`

```

```

Response Data
-------------

[](#response-data)

- How to retrieve data

### Get Message

[](#get-message)

- This will return error message

```
$file = File::name('html_input_name');

$file->getMessage();

// This will change the message text
$file->getMessage('new Message');

```

### Get Status

[](#get-status)

- This will return error status code

```
$file = File::name('html_input_name');

$file->getStatus();

```

### Get Class

[](#get-class)

- This will only return msg, if there's an error or success

```
$file = File::name('html_input_name');

$file->getClass();

```

### First

[](#first)

- This will get the first uploaded data
    - \[optional\] You can pass the mode as string `name` | `path`|`url`

```
->save(function($response){

    $response->first();
});

```

- `or`

```
$upload = File::name('avatar')
                ->save();

$upload->first('url);

```

### Get

[](#get)

- This will get all uploaded data
    - Returns an index array of all uploaded data, `[name, path, url]`
    - \[optional\] You can pass the mode as string `name` | `path`|`url`

```
->save(function($response){

    $response->get();
});

```

- `or`

```
$upload = File::name('avatar')
            ->save();

$upload->get('name);

```

### Form

[](#form)

- Return form request data
    - This will return `validator package` object [Validator](https://github.com/tamedevelopers/validator)

```
->save(function($response){

    $response->form();
});

```

### Unlink

[](#unlink)

- Accepts two param as string. This method uses the base path automatically.
    - \[mandatory\] `$fileToUnlink` Path to file, you want to unlink.
    - \[optional\] `$checkFile`. This will check if `$fileToUnlink` is not same, before.

```
->save(function($response){

    $userAvatar;

    $response->unlink("public/images/{$userAvatar}", "avatar.svg");

});

```

Usage
-----

[](#usage)

### Name

[](#name)

- Takes one param `string` as input name
    - Static method by default

```
File::name('html_input_name');

```

### Driver

[](#driver)

- More drivers are to be added in the future
    - By default driver is set to `local`

KeyDescriptions3Amazon `s3` driver. The package loaded `[Ec2 and CloudWatch]` needed by s3localLocal `host server` driver.```
File::name('avatar')
    ->driver('s3');

```

- `using driver if project is not in any Frameworks`

```
use Tamedevelopers\Support\Env;

// if your project is not on on core php, then you'll need to load env.
// this will create env dummy data and as well load the .env file.
// once data has been created, you can remove the `Env::createOrIgnore();`

Env::createOrIgnore();
Env::load();

File::name('avatar')
    ->driver('s3');

```

### BaseDir

[](#basedir)

- Takes one param `string` as base directory name
    - This will override the global configuration settings (Domain and Server Path will be set)

```
File::name('avatar')
    ->baseDir('newBaseDirectory');

```

### Generate

[](#generate)

- Takes one param `bool`

```
File::name('avatar')
        ->generate(false);

```

### Folder

[](#folder)

- Takes one param `string` as `folder_path` to save file

```
File::name('avatar')
    ->folder('upload/user');

```

### Filter

[](#filter)

- Takes index or closed array index
    - Removse `error status code` you do not want to validate
    - You cannot remove Error `200`

Status CodeDescription401Select file to upload402File upload is greater than allowed size of403Maximum file upload exceeded. Limit is404Uploaded file format not allowed. Allowed formats405Image dimension allowed is200File uploaded successfully```
File::name('avatar')
    ->filter(401, 402);

```

- `or`

```
File::name('avatar')
    ->filter([401, 402, 405]);

```

### filterExtention

[](#filterextention)

- Takes index or closed array index
    - Removes `file extention and mime-types` you do not want to validate

```
File::name('avatar')
    ->filterExtention('png', 'gif');

```

- `or`

```
File::name('avatar')
    ->filterExtention(['png', 'gif']);

```

### Structure

[](#structure)

- Takes one param `string` as `structure type`
    - Best used for `Media\|Blog\|Newsletter` Websites.

KeyDescriptiondefaultFiles will be uploaded in defaut folder pathyearFiles will be uploaded in `default/year` path: `folder/yyyy`monthFiles will be uploaded in `default/year` path: `folder/yyyy/mm`dayFiles will be uploaded in `default/year` path: `folder/yyyy/mm/dd`1. Default
    - Year
        - Month
            - Day

```
File::name('avatar')
    ->structure('month');

```

### Size

[](#size)

- Takes one param `string` | `int`
    - size in `int` | `kb` | `mb` | `gb`

```
File::name('avatar')
    ->size('1.5mb'); // will be converted to:  1.5 * (1024 * 1024) = 1572864

```

- `or`

```
File::name('avatar')
    ->size(2097152); // = 2097152|2mb

```

### Limit

[](#limit)

- Takes one param `string` | `int`
    - Default limit is set to `1` upload

```
File::name('avatar')
    ->limit(2);

```

### Mime

[](#mime)

- Takes one param `string` as mime type
    - Goto `Mime Types` to see list

```
File::name('avatar')
    ->mime('image');

```

### Width

[](#width)

- Takes two param `string` | `int` and `bool`
    - 1st param is `string` | `int`. width size
    - 2nd param is `bool`. This allow to check if size should be === or &gt;= size of uploaded image. Default is `true`

```
$file = File::name('avatar')
        ->width(700, false);

dd(
    $file
);

```

### Height

[](#height)

- Same as `width` method

```
File::name('avatar')
    ->width(700)
    ->height(400);

```

### Validate

[](#validate)

- \[optional\] Method can be use, to return error message.
    - Takes an \[optional\] param as a `callable\|closure` function.

```
File::name('banner')
    ->folder('upload/banner')
    ->validate(function($response){

        // perform any other needed task in here
        echo $response->getMessage();
        return;
    });

```

### Save

[](#save)

- Takes an \[optional\] param as a `callable\|closure` function.
    - Calling this \[method\] will automatically save the data.

```
File::name('banner')
    ->folder('upload/banner')
    ->save(function($response){

        // perform any other needed task in here
    });

```

- `or`

```
$file = File::name('banner')
            ->folder('upload/banner')
            ->save();

dd(
    $file->get(),
    $file->first(),
);

```

### Resize

[](#resize)

- Takes two param as `size` `int` width and height
    - Returns an instance of self

```
File::name()
    ->folder('upload/banner')
    ->save(function($response){

        // perform resize
        // width, height
        $response->resize(400, 400);
    });

```

### WaterMark

[](#watermark)

- Takes three param `watermarkSource` | `position` | `padding`
    - \[mandatory\] $watermarkSource
    - Returns an instance of self
    - Padding is applied evenly on all position apart from `center`

Position keyDescriptionbottom-rightDefault is `bottom-right`bottom-leftapply watermart to possition `bottom-left`top-rightapply watermart to possition `top-right`top-leftapply watermart to possition `top-left`centerapply watermart to possition `center````
File::name('avatar')
    ->folder('upload/banner')
    ->save(function($response){

        // perform watermark
        $response->watermark('watermark.png', 'center', 50);
    });

```

### Compress

[](#compress)

- Returns an instance of self

```
File::name('avatar')
    ->folder('upload/banner')
    ->save(function($response){

        // perform compressor
        $response->compress();

        // you can perform method chaining as well
        $response->resize(200, 450)
                    ->watermark('watermark.png', 'center')
                    ->compress();

    });

```

### Get External Image Size

[](#get-external-image-size)

- Takes one param as `string`
    - Return an `array` | `null`

```
File::getImageSize('full_source_path')

[
  ["height"]    => int(4209)
  ["width"]     => int(3368)
]

```

### Get Uploaded Image Size

[](#get-uploaded-image-size)

- Takes one param as `string`
    - Return an `array` | `null`

```
File::imageSize('name_of_uploaded_file')

[
  ["height"]    => int(4209)
  ["width"]     => int(3368)
]

```

### Get Mime Type

[](#get-mime-type)

- Takes one param as `string`
    - Return `string` | `bool`. `false` on error.

```
File::getMimeType('full_source_path')

```

### Not Empty

[](#not-empty)

- Takes one param as `string`. Input file name
    - Return bool `true` | `false`

```
File::notEmpty('avatar');
File::isNotEmpty('avatar');
File::has('avatar');

```

### Is Empty

[](#is-empty)

- Same as not empty

```
File::isEmpty('avatar')

```

### Has Error

[](#has-error)

- Returns true or false. Check if there's an error in the upload

```
$file = File::name('avatar')

if($file->hasError()){

}

```

### Is Completed

[](#is-completed)

- Returns true or false. Check if upload has been completed

```
$file = File::name('avatar')

if($file->isCompleted()){

}

```

### Mime Types

[](#mime-types)

KeyDescriptionvideo`.mp4|.mpeg|.mov|.avi|.wmv`audio`.mp3|.wav`file`.docx|.doc|.pdf|.txt`image`.jpg|.jpeg|.png|.gif`zip`.zip|.rar`pdf`.pdf`xls`.xlsx|.xls|.csv`doc`.docx|.doc|.txt`general\_image`.jpg|.jpeg|.png|.gif|.webp|.ico`general\_media`.mp3|.wav|.mp4|.mpeg|.mov|.avi|.wmv`general\_file`.docx|.doc|.pdf|.txt|.zip|.rar|.xlsx|.xls|.csv````
File::name('invoiceDescription')
    ->mime('zip')
    ->save();

```

Useful Links
------------

[](#useful-links)

- @author Fredrick Peterson (Tame Developers)
- If you love this PHP Library, you can [Buy Tame Developers a coffee](https://www.buymeacoffee.com/tamedevelopers)

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance86

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~31 days

Recently: every ~43 days

Total

29

Last Release

70d ago

Major Versions

1.0.9 → 2.0.02023-10-08

2.0.12 → 3.02024-07-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/d363c130739125512fda1ddbac6287f43d4eac8bd96808d44cdd525737c16486?d=identicon)[tamedevelopers](/maintainers/tamedevelopers)

---

Top Contributors

[![tamedevelopers](https://avatars.githubusercontent.com/u/52910237?v=4)](https://github.com/tamedevelopers "tamedevelopers (19 commits)")

---

Tags

filefile-uploaderimageimage-uploaderphp-image-uploaderimagefileuploaderfile-uploaderimage-uploaderphp image uploader

### Embed Badge

![Health badge](/badges/tamedevelopers-file/health.svg)

```
[![Health](https://phpackages.com/badges/tamedevelopers-file/health.svg)](https://phpackages.com/packages/tamedevelopers-file)
```

###  Alternatives

[kartik-v/bootstrap-fileinput

An enhanced HTML 5 file input for Bootstrap 5.x, 4.x, and 3.x with features for file preview for many file types, multiple selection, ajax uploads, and more.

5.4k7.9M13](/packages/kartik-v-bootstrap-fileinput)[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[fof/upload

The file upload extension for the Flarum forum with insane intelligence.

188171.7k15](/packages/fof-upload)[mohorev/yii2-upload-behavior

Upload behavior for Yii 2

128265.5k9](/packages/mohorev-yii2-upload-behavior)[transloadit/php-sdk

Transloadit SDK

63393.6k2](/packages/transloadit-php-sdk)[tilleuls/ckeditor-sonata-media-bundle

Integrates SonataMediaBundle with CKEditor

53531.4k1](/packages/tilleuls-ckeditor-sonata-media-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
