PHPackages                             reshadman/file-secretary - 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. reshadman/file-secretary

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

reshadman/file-secretary
========================

Get rid of anything related to files in Laravel, This package handles all for you. Anything we mean.

1.1.12(5y ago)1131.8k7MITPHPCI failing

Since Aug 29Pushed 4y ago2 watchersCompare

[ Source](https://github.com/reshadman/file-secretary)[ Packagist](https://packagist.org/packages/reshadman/file-secretary)[ Docs](https://github.com/reshadman/file-secretary)[ RSS](/packages/reshadman-file-secretary/feed)WikiDiscussions master Synced 2w ago

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

Notice Before Usage
===================

[](#notice-before-usage)

For new versions of Laravel use [spatie/laravel-medialibrary](https://github.com/spatie/laravel-medialibrary). The funcionality is almost the same except that the same files are stored multiple times. As a recommendation if you want image resizing functionality use something like [thumbor](https://github.com/thumbor/thumbor) which is more stable, secure, configurable and fast.

Laravel File Secretary
======================

[](#laravel-file-secretary)

[![Build Status](https://camo.githubusercontent.com/3912ba3066a6bad02875902271915a39059cf55b715d12549455d01c6f2c4323/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f7265736861646d616e2f66696c652d7365637265746172792f6d61737465722e706e673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/3912ba3066a6bad02875902271915a39059cf55b715d12549455d01c6f2c4323/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f7265736861646d616e2f66696c652d7365637265746172792f6d61737465722e706e673f7374796c653d666c61742d737175617265)[![Build Status](https://camo.githubusercontent.com/d08adcea54be6d07d03f618cbc03b56adbfcbe2377ba9ece41db00591b39e2b1/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3539613431303435333638623038303033663137326134312f62616467652e706e673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d08adcea54be6d07d03f618cbc03b56adbfcbe2377ba9ece41db00591b39e2b1/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3539613431303435333638623038303033663137326134312f62616467652e706e673f7374796c653d666c61742d737175617265)

Get rid of anything related to files in Laravel, This package handles all for you.

What does this package do?
--------------------------

[](#what-does-this-package-do)

1. **Handles your public assets** (.css, .js, .etc) you can use your CDN provider to serve the static assets. with a simple function call. For instance you can serve your static files through Rackspace CDN. After each deploy a new unique id is assigned to the path so the cached assets would be purged.
2. **Image manipulation and storage**: Store all of your images in the cloud (based on Laravel Adapters, Rackspace, S3, minio etc.), The image resizing is handled with simple configuration. You define templates and then images are generated automatically. Once a new image template created, you can use the nginx directives included in the package to remove the participation of PHP in next calls. Read the documentation for more info. A simple, fast and reliable method to manipulate images that are stored in the cloud.
3. **Detects redundant files**, File names are generated based on the filesize + a hash function. so redundant files could not exist technically, You can implement your own file name generator, too.
4. **Storing files** with a simple method call. They can be served without the participation of PHP, and they can be addressed with the package's helper functions if they are public.
5. **Database Tracking** (Optional), Centerialized Eloquent model which tracks your stored files(and images), You can store files/resiable-images and attach them to your bussiness models. Then you can use them. If it is an Image the templates are accessible by simple getters in the model.
6. **Simple helper functions** for dealing with resizable image urls, file urls, asset urls etc.
7. **A Simple controller for serving private/public files** Serve both resizable images, and files. You can implement your own access control for restricting access on request. So for instance if the file should be only served to its uploader, you can implement an access controller which checks that the requested file is attached to the user model or not.

Getting Started
---------------

[](#getting-started)

- [Does this package fit my needs?](#does-this-package-fit-my-needs)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Terminology](#terminology) : read for faster understanding.
    - [Defining Contexts](#defining-contexts)
    - [Using the asset uploader](#using-the-asset-uploader)
    - [Storing files](#storing-files)
        - [File names](#file-names)
        - [Storing Service(Command)](#storing-command)
        - [Storable file with file path](#storable-file-with-file-path)
        - [Storable file with file content](#storable-file-with-file-content)
        - [Storable file with file instance](#storable-file-with-file-instance)
        - [Storable file with file HTTP url](#storable-file-with-file-http-url)
        - [Storable file with base64 encoded content](#storable-file-with-base64-encoded-content)
        - [Stored File Resoponse](#stored-file-response)
    - [Storing images](#storing-images)
    - [Deleting files](#deleting-files)
    - [Updating files](#updating-files)
    - [Manipulating images](#manipulating-images)
        - [Image Templates](#image-templates)
        - [Using the dynamic generic template](#using-the-dynamic-generic-template)
        - [Writing your own template](#writing-your-own-template)
        - [Storing manipulated image](#storing-manipulated-image)
    - [Storing Eloquent-tracked files](#storing-eloquent-tracked-files)
        - [When to use tracked files](#when-to-use-tracked-files)
        - [Storing simple files and manupulateable images](#storing-simple-files-and-manipulatable-images)
        - [Storing manipulatable images](#storing-manipulatable-images)
        - [Using your own model](#using-your-own-model)
    - [Deleting Eloquent-tracked files](#deleting-eloquent-tracked-files)
        - [Handle what happens on delete](#handle-what-happens-on-delete)
    - [Serving files](#serving-files)
        - [Default Routes](#default-routes)
        - [Restricting access](#restricting-access)
        - [Serving public files and manipulated images](#serving-public-files-and-manipulated-images)
        - [Serving images without the participation of PHP](#serving-images-without-the-participation-of-php)
    - [Helper functions](#helper-functions)
    - [Nginx Directives And Production Notes](#nginx-directives-and-production-notes)

Does this package fit my needs?
-------------------------------

[](#does-this-package-fit-my-needs)

 offers some practical specs for dealing with files, called *attached resources*. As files are an important part of the most of the information systems, they should be stored in a reliable, fast third party service (Like Amazon S3, or Rackspace object storage).

This package is an implementation of an spec for making Laravel application 12factor compatible for attached resources. You can follow the spec with your own implementation.

[![Attached Resources](https://camo.githubusercontent.com/951c4d50e2a1a5c1313136cbbab86a77643d8a50c33fdfa5d7cc2675d9e03998/68747470733a2f2f3132666163746f722e6e65742f696d616765732f61747461636865642d7265736f75726365732e706e67)](https://camo.githubusercontent.com/951c4d50e2a1a5c1313136cbbab86a77643d8a50c33fdfa5d7cc2675d9e03998/68747470733a2f2f3132666163746f722e6e65742f696d616765732f61747461636865642d7265736f75726365732e706e67)

So if your application domain is not about files (You are not Dropbox or Amazon S3 itself :D). You can follow the spec and use the features this package offers, There are typically some main usecases for files:

- Serving private/public files (Like PDF, Docs etc)
- Serving manipulatable images (Images that should be re-sized, watermarked etc), which is computation/memory heavy.
- Serving static assets (like css, js, svg) etc.
- Attaching and tracking business domain files to their equivalent business model (Like the profile image of a user)

Laravel file-secretary offers some simple solutions for the above needs. We did not apart the package to individual ones to respect the simplicity. The interface that this package offers could be much simpler and more performant as Laravel file-secretary has been developed periodically it is not in its simplest shape. We will keep that in mind for next releases.

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

[](#installation)

Run the following command in your project directory, to add the package to `composer.json`:

```
composer require reshadman/file-secretary ">=1.0.0
