PHPackages                             alaaelgndy/file-uploader - 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. alaaelgndy/file-uploader

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

alaaelgndy/file-uploader
========================

This is a file file-uploader manager

131303PHP

Since May 14Pushed 5y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Media management package.
-------------------------

[](#media-management-package)

#### Why do you need this package?

[](#why-do-you-need-this-package)

- it can handle all of your needs to manage you application media.
- it provides an API to make life easy for the consumers (client side devs).
- it will help the client side devs to make an reusable component for the media uploads.
- if you are creating an back-end system and your whole APIs are using json, you still not have a need to use base64 for you media.

#### How it works?

[](#how-it-works)

- generate a temp path for the your uploaded file by using the exposed API for uploading media.
- upload the file in this temp path on the configured storage.
- return the base url of you storage and the temp path.
- so this file is exist in the temp path but till now nothing has used it (it's still temp file).
- but client side developers can preview it using the base url and the temp path.
- then you can relate this file to any model in you application.
- using this event (Elgndy\\FileUploader\\Events\\UploadableModelHasCreated)

#### What is the temp path?

[](#what-is-the-temp-path)

- the temp path is the place we use to hold the media in the early stage.
- it contains 4 parts.

1. the temp folder (you can configure it).
2. the related model.
3. the type of this media (you can custom your own types).
4. the file name.

#### What is the real path?

[](#what-is-the-real-path)

- the real path is the final place for this file.
- it contains 4 parts.

1. the related model.
2. the related id.
3. the type of this media.
4. the filen name.

#### Contract of the API.

[](#contract-of-the-api)

- API for uploading
- URL /upload-media
- METHOD post.
- HEADER (content type: multipart/encrypted)
- BODY (model: string, mediaType: string, media: file)

### Installation

[](#installation)

```
composer require alaaelgndy/file-uploader

```

### Usage

[](#usage)

- configure your models namespace like (App\\)
- configure your temp path, the default is (temp/).
- update your models to implement (Elgndy\\FileUploader\\Contracts\\FileUploaderInterface).
- use Uploadable trait in your uploadable models.
- implement this function getMediaTypesWithItsOwnValidationRules()
    - the keys are the mediaType
    - the values are the available extensions for this specefic mediaType.

```
