Download the PHP package khaleghi/media without Composer
On this page you can find all versions of the php package khaleghi/media. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download khaleghi/media
More information about khaleghi/media
Files in khaleghi/media
Package media
Short Description This will store files in server and save their attributes to database
License
Informations about the package media
Media store
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
PHP >= 5.4
Installation
Run the following command:
Then run the following:
You have to make a link between public
folder and storage
by running this command:
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
Saving Images
Let's make a form in a html file:
Then make a route like this:
Now, All ever we have to do in our controller is:
We can display the image like this:
Responsive images
By default, The image we store in a way like above will be saved in 4 paths:
You can access url of each path by sending these parameters:
Fill free to change default image sizes at config\media.php
Note:
khaleghi/media-store
uses Intervension Image package to change dimension of images. It will be installed on your project as a dependency.
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:
Polymorphism
The Medium
model is a polymorphic class. So you can make a relation between your other models to this model.
Now you can access to user's file:
And reverse access:
Note: Don't forget to use morphMany in medium's related model (here: App\User).
Determine before saving
You can make an instance of medium
model and change it's attribute before save it:
Delete a medium
To delete a medium from Storage and Database you need to use remove
method:
Database
These fields will be stored in database and you are able to access them through instance of Medium model:
Field Name | Usage |
---|---|
stored_name | The name that file will store in storage folder |
file_name | Original name of the file |
caption | |
mime | |
size | Size of the file in bytes |
width | Just for images |
height | Just for images |
mediumable_type | Name of model that this file is related to it |
mediumable_id | model primary key that this file is related to it |
position | Assigning a priority to each file with same manner of mediumable_type |
manner | What this file is good for. Example: avatar |
comments_count | |
likes_count | |
description |
License
Media-store is free software distributed under the terms of the MIT license.