Download the PHP package czim/laravel-paperclip without Composer

On this page you can find all versions of the php package czim/laravel-paperclip. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-paperclip

Latest Version on Packagist Build Status Coverage Status

Laravel Paperclip: File Attachment Solution

Allows you to attach files to Eloquent models.

This is a re-take on CodeSleeve's Stapler. It is mainly intended to be more reusable and easier to adapt to different Laravel versions. Despite the name, this should not be considered a match for Ruby's Paperclip gem.

Instead of tackling file storage itself, it uses Laravel's internal storage drivers and configuration.

This uses czim/file-handling under the hood, and any of its (and your custom written) variant manipulations may be used with this package.

Version Compatibility

Laravel Package PHP Version
5.4 and below 1.0, 2.1 7.4 and below
5.5 1.5, 2.5 7.4 and below
5.6, 5.7 2.6 7.4 and below
5.8, 6 2.7 7.4 and below
7, 8 3.2 7.4 and below
7, 8, 9 4.0 8.0 and up
9 and up 5.0 8.1 and up

Change log

View the changelog.

Installation

Via Composer:

Auto-discover may be used to register the service provider automatically. Otherwise, you can manually register the service provider in config/app.php:

Publish the configuration file:

Set up and Configuration

Model Preparation

Modify the database to add some columns for the model that will get an attachment. Use the attachment key name as a prefix.

An example migration:

Replace attachmentname here with the name of the attachment. These attributes should be familiar if you've used Stapler before.

A <key>_variants text or varchar column is optional:

A text() column is recommended in cases where a seriously huge amount of variants are created.

If it is added and configured to be used (more on that in the config section), JSON information about variants will be stored in it.

Attachment Configuration

To add an attachment to a model:

Note: If you perform the hasAttachedFile() call(s) after the parent::__construct() call, everything will work the same, except that you cannot assign an image directly when creating a model. ModelClass::create(['attachment' => ...]) will not work in that case.

Since version 2.5.7 it is also possible to use an easier to use fluent object syntax for defining variant steps:

Variant Configuration

For the most part, the configuration of variants is nearly identical to Stapler, so it should be easy to make the transition either way.

Since version 2.6, Stapler configuration support is disabled by default, but legacy support for this may be enabled by setting the paperclip.config.mode to 'stapler'.

Get more information on configuration here.

Custom Variants

The file handler comes with a few common variant strategies, including resizing images and taking screenshots from videos. It is easy, however, to add your own custom strategies to manipulate files in any way required.

Variant processing is handled by the file-handler package. Check out its source to get started writing custom variant strategies.

Storage configuration

You can configure a storage location for uploaded files by setting up a Laravel storage (in config/filesystems.php), and registering it in the config/paperclip.php config file.

Make sure that paperclip.storage.base-urls.<your storage disk> is set, so valid URLs to stored content are returned.

Hooks Before and After Processing

It is possible to 'hook' into the paperclip goings on when files are processed. This may be done by using the before and/or after configuration keys. Before hooks are called after the file is uploaded and stored locally, but before variants are processed; after hooks are called when all variants have been processed.

More information and examples are in the Config section.

Events

The following events are available:

Refreshing models

When changing variant configurations for models, you may reprocess variants from previously created attachments with the paperclip:refresh Artisan command.

Example:

Usage

Once a model is set up and configured for an attachment, you can simply set the attachment attribute on that model to create an attachment.

Setting attachments without uploads

Usually, you will want to set an uploaded file as an attachment. If you want to store a file from within your application, without the context of a request or a file upload, you can use the following approach:

Clearing attachments

In order to prevent accidental deletion, setting the attachment to null will not destroy a previously stored attachment. Instead you have to explicitly destroy it.

Differences with Stapler

If you wish to force storing the contents of a URL without letting Paperclip interpret it, you have some options. You can use the Czim\FileHandling\Storage\File\StorableFileFactory@makeFromUrl method and its return value. Or, you can download the contents yourself and store them in a Czim\FileHandling\Storage\File\RawStorableFile (e.g.: (new RawStorableFile)->setData(file_get_contents('your-URL-here'))). You can also download the file to local disk, and store it on the model through an \SplFileInfo instance (see examples on the main readme page).

Amazon S3 cache-control

If you use Amazon S3 as storage disk for your attachments, note that you can set Cache-Control headers in the options for the filesystems.disks.s3 configuration key. For example, to set max-age headers on all uploaded files to S3, edit config/filesystems.php like so:

Upgrade Guide

Upgrading from 1.5. to 2.5.

Estimated Upgrade Time: 5 - 10 Minutes

Updating Dependencies

Update your czim/laravel-paperclip dependency to ^2.5 in your composer.json file.

Then, in your terminal run:

In addition, if you are using the czim/file-handling package directly, you should upgrade the package to its ^1,0 release, but be sure to checkout the CHANGELOG

Update Configuration

Update your config/paperclip.php file and replace:

With:

This should now include placeholders to make a full file path including the filename, as opposed to only a directory. Note that this makes the path interpolation logic more in line with the way Stapler handled it.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-paperclip with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
czim/file-handling Version ^2.3
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package czim/laravel-paperclip contains the following files

Loading the files please wait ....