PHPackages                             khaleghi/media - 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. [Image &amp; Media](/categories/media)
4. /
5. khaleghi/media

ActiveLibrary[Image &amp; Media](/categories/media)

khaleghi/media
==============

This will store files in server and save their attributes to database

v1.1.3(6y ago)546PHPPHP ^7.1.3CI failing

Since Jan 25Pushed 6y ago3 watchersCompare

[ Source](https://github.com/Saeid-Khaleghi/media-store)[ Packagist](https://packagist.org/packages/khaleghi/media)[ RSS](/packages/khaleghi-media/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (8)Used By (0)

Media store
===========

[](#media-store)

[![Build Status](https://camo.githubusercontent.com/7da756a98243fbea13b4d6053ff6131754305c01c7d2c1b6b7b30e81e92bb03e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f53616569642d4b68616c656768692f6d656469612d73746f72652f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Saeid-Khaleghi/media-store/build-status/master)[![Issues](https://camo.githubusercontent.com/6f1a4fe0323dd2c7d447b9f1540f7e74efb40cc968bfc40a2549f438e5dc82b2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f53616569642d4b68616c656768692f6d656469612d73746f72652e7376673f7374796c653d666c61742d737175617265)](https://github.com/Saeid-Khaleghi/media-store/issues)[![Forks](https://camo.githubusercontent.com/8e1d556e2e9e3b1804894e4dc83d378eea7fab46cd51e03113a1309accb8d645/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f53616569642d4b68616c656768692f6d656469612d73746f72652e7376673f7374796c653d666c61742d737175617265)](https://github.com/Saeid-Khaleghi/media-store/network/members)[![Stars](https://camo.githubusercontent.com/8ae681a9891af3224d4b56dbce54fba583510a667c2a9d4c2e11864b6b42699d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f53616569642d4b68616c656768692f6d656469612d73746f72652e7376673f7374796c653d666c61742d737175617265)](https://github.com/Saeid-Khaleghi/media-store/stargazers)[![Total Downloads](https://camo.githubusercontent.com/3b72ed1226c5b2c23b8e8d737c666bde86d949664f81843bc9c3be18199f9768/68747470733a2f2f706f7365722e707567782e6f72672f6b68616c656768692f6d656469612f642f746f74616c2e737667)](https://packagist.org/packages/khaleghi/media)

`khaleghi/media-store` is a Laravel package which created to provide an easy way to store any kind of files on server storage and save their attributes in the database. The other purpose of this package is to store images in a way that to be used in various responsive dimensions. This package is supported and tested in Laravel 5.4 and above.

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

[](#requirements)

PHP &gt;= 5.4

### Installation

[](#installation)

Run the following command:

```
composer require khaleghi/media
```

Then run the following:

```
php artisan vendor:publish --provider="Khaleghi\Media\MediaServiceProvider"

php artisan migrate
```

You have to make a link between `public` folder and `storage` by running this command:

```
php artisan storage:link
```

Configuration
-------------

[](#configuration)

Set the property values in the config/media.php. These values will be used by media-store to make proper image sizes and customized upload folder.

Usage
-----

[](#usage)

### Saving Images

[](#saving-images)

Let's make a form in a html file:

```

    @csrf

        Select your file:

            Upload

```

Then make a route like this:

```
Route::post('media', 'YourController@YourMethod')->name('media.store');
```

Now, All ever we have to do in our controller is:

```
use Khaleghi\Media\Medium;

public function YourMethod(Request $request){
    if($request->has('photo')){
        $medium = Medium::create([
            'file' => $request->file('photo'),
        ]);

        return back()->with('photo_url', $medium->url());
    }
}
```

We can display the image like this:

```

```

#### Responsive images

[](#responsive-images)

By default, The image we store in a way like above will be saved in 4 paths:

```
storage\app\public\images\lg    (Original Image size)
storage\app\public\images\md    (540 x 540 px)
storage\app\public\images\sm    (270 x 270 px)
storage\app\public\images\xs    (135 x 135 px)

```

You can access url of each path by sending these parameters:

```
$medium->url('lg') //default
$medium->url('md') // medium size
$medium->url('sm') // small size
$medium->url('xs') // extra small size

```

**Fill free to change default image sizes at config\\media.php**

> **Note:** `khaleghi/media-store` uses [Intervension Image](http://http://image.intervention.io//) package to change dimension of images. It will be installed on your project as a dependency.

### Saving other file types

[](#saving-other-file-types)

You can store all other file types in a way that mentioned before. They will save in these paths related to their mime types:

```
storage\app\public\applications
storage\app\public\auduis
storage\app\public\videos
storage\app\public\texts
...

```

### Polymorphism

[](#polymorphism)

The `Medium` model is a polymorphic class. So you can make a relation between your other models to this model.

```
$medium = Medium::create([
    'file' => $request->file('name'),
    'mediumable_type' => 'App\User',
    'mediumable_id' => 10
]);
```

Now you can access to user's file:

```
$user = App\User::find(10);
$file = $user->media->first();
echo $file->url();
```

And reverse access:

```
echo $medium->mediumable->email;
```

> **Note:** Don't forget to use morphMany in medium's related model (here: App\\User).

```
public function media(){
    return $this->morphMany(Medium::class, 'mediumable');
}
```

### Determine before saving

[](#determine-before-saving)

You can make an instance of `medium` model and change it's attribute before save it:

```
$medium = new Medium();
$medium->attach_file($request->file('name'));
$medium->description = "Occupational and educational information";
if($medium->size < 102400 and $medium->extension == "jpg"){
    $medium->save();
}else{
    $medium->detach();
    return "Error";
}
```

Delete a medium
---------------

[](#delete-a-medium)

To delete a medium from Storage and Database you need to use `remove` method:

```
$medium->remove();
```

Database
--------

[](#database)

These fields will be stored in database and you are able to access them through instance of Medium model:

Field NameUsagestored\_nameThe name that file will store in storage folderfile\_nameOriginal name of the filecaptionmimesizeSize of the file in byteswidthJust for imagesheightJust for imagesmediumable\_typeName of model that this file is related to itmediumable\_idmodel primary key that this file is related to itpositionAssigning a priority to each file with same manner of mediumable\_typemannerWhat this file is good for. Example: avatarcomments\_countlikes\_countdescriptionLicense
-------

[](#license)

Media-store is free software distributed under the terms of the MIT license.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 96.8% 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 ~56 days

Recently: every ~70 days

Total

6

Last Release

2383d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/823090fd96e055df2e2f6af5a93b492f5370d5995889465102827f4d1d246216?d=identicon)[calampolow](/maintainers/calampolow)

---

Top Contributors

[![Saeid-Khaleghi](https://avatars.githubusercontent.com/u/13361616?v=4)](https://github.com/Saeid-Khaleghi "Saeid-Khaleghi (30 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

gdimagelaravelpackageresponsive-imagesthumbnail

### Embed Badge

![Health badge](/badges/khaleghi-media/health.svg)

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

###  Alternatives

[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[justbetter/statamic-image-optimize

Image optimization after upload

1315.2k](/packages/justbetter-statamic-image-optimize)

PHPackages © 2026

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