Download the PHP package awaisjameel/base64filehandler without Composer

On this page you can find all versions of the php package awaisjameel/base64filehandler. 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 base64filehandler

Base64 File Handler

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Base64FileHandler decodes data: URI / raw base64 payloads — the kind you get from a JS canvas export, a signature pad, or a mobile app's JSON upload — validates them, and stores them on any Laravel filesystem disk. It resolves MIME types and extensions using awaisjameel/mimetypes, so file-type detection stays accurate without a hardcoded, ever-stale lookup table baked into this package.

Features

Requirements

Base64FileHandler PHP Laravel
^3.0 ^8.2 ^12.0, ^13.0

The fileinfo PHP extension is required. Laravel 12 supports PHP 8.2–8.5; Laravel 13 requires PHP 8.3–8.5. Development installs use the latest compatible Pest version (3 on PHP 8.2, 4 on PHP 8.3 or Laravel 12, and 5 on PHP 8.4–8.5 with Laravel 13).

Upgrading from 2.x

Version 3 drops Laravel 10 and 11. MIME types are now detected from the decoded bytes for every upload. A data URI declaring a different type throws MimeTypeMismatchException before storage or image validation. Correct mislabeled uploads at their source; raw base64 remains supported. Data URI metadata is matched case-insensitively, and parameters such as charset=UTF-8 are accepted.

isValidImage() requires an image MIME type and recognizable image dimensions in addition to the configured extension list. It inspects image metadata; it does not fully decode pixels or sanitize image content. Storage failures return the package's UnableToStoreFileException, preserving any underlying filesystem exception.

Installation

Install the package via Composer:

The service provider and Base64FileHandler facade are auto-discovered — there's nothing else to register.

Optionally publish the config file:

This is the config that gets published:

Usage

The recommended way to use the package is through its facade — resolving it this way always honours your published config and any runtime config() overrides:

Prefer dependency injection? The underlying AwaisJameel\Base64FileHandler\Base64FileHandler class is bound as a singleton in the container, so you can type-hint it anywhere:

Storing a base64 file

$base64Data may be a full data URI (data:image/png;base64,...) or a raw base64 string with no prefix. The MIME type is detected from the decoded bytes, and a supplied MIME label must match it. The returned $path is the file's path on the given disk (suitable for Storage::disk($disk)->url($path), ->get($path), etc.).

If originalName is given, its slugified filename is used as a prefix so stored paths stay readable; a unique suffix is always appended so concurrent uploads — even of the same original filename — never collide or overwrite one another.

Validating that base64 data is an image

Inspecting base64 data without storing it

Exceptions

Every method throws a specific exception for each failure mode instead of a generic Exception, so you can catch exactly what you expect:

Exception Thrown when
AwaisJameel\Base64FileHandler\Exceptions\InvalidBase64DataException The given string isn't valid base64 data.
AwaisJameel\Base64FileHandler\Exceptions\UnableToDetermineMimeTypeException The decoded content's MIME type couldn't be detected.
AwaisJameel\Base64FileHandler\Exceptions\MimeTypeMismatchException The data URI's MIME label conflicts with the decoded content.
AwaisJameel\Base64FileHandler\Exceptions\UnsupportedFileExtensionException The resolved file extension isn't in the allowed extensions list (store() only).
AwaisJameel\Base64FileHandler\Exceptions\InvalidImageException The extension is disallowed or the decoded content lacks an image MIME type and recognizable dimensions (isValidImage() only).
AwaisJameel\Base64FileHandler\Exceptions\UnableToStoreFileException The filesystem disk rejected the write (store() only).

All of the above extend the package's base AwaisJameel\Base64FileHandler\Exceptions\Base64FileHandlerException, so you can catch everything this package itself throws in one place:

Resolving a MIME type or extension is delegated to awaisjameel/mimetypes, which can itself throw AwaisJameel\MimeTypes\Exceptions\UnknownMimeTypeOrExtensionException (an unrecognized MIME type/extension) or AwaisJameel\MimeTypes\Exceptions\UnableToFetchMimeTypesException (its MIME type source is unreachable and its offline fallback has been disabled). Both extend AwaisJameel\MimeTypes\Exceptions\MimeTypesException — catch that too if you want a single catch block covering everything either package can throw:

Configuration reference

Key Env variable Default Description
disk BASE64_FILE_HANDLER_DISK public The default filesystem disk files are stored on.
path BASE64_FILE_HANDLER_PATH uploads/ The default path within the disk files are stored under.
allowed_extensions — [] (all allowed) Extensions store() will accept. Matched case-insensitively.
valid_image_extensions — ['jpeg', 'jpg', 'png', 'gif', 'webp'] Extensions isValidImage() treats as images. Matched case-insensitively.

Every option above can also be overridden per call via store()'s and isValidImage()'s optional arguments, or by constructing the class directly with a custom config array:

Note that a directly-instantiated new Base64FileHandler(...) does not read your published config file — it only uses the defaults above merged with whatever you pass in. Resolve it via the facade or the container (as shown under Usage) if you want your published config file honoured.

Testing

The package's MimeTypes dependency resolves its data over HTTP; the test suite fakes that request (see tests/TestCase.php) so tests run fully offline and deterministically, using the bundled MIME type snapshot as a fallback. Keep that in mind if you write your own tests against this package — fake the same way, or Http::fake() a MIME type response yourself.

Or with coverage:

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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


All versions of base64filehandler with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-fileinfo Version *
awaisjameel/mimetypes Version ^2.0||^3.0
illuminate/filesystem Version ^12.0||^13.0
illuminate/support Version ^12.0||^13.0
league/flysystem Version ^3.36.0
spatie/laravel-package-tools Version ^1.93.3
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 awaisjameel/base64filehandler contains the following files

Loading the files please wait ...