PHP library that provides a filesystem abstraction layer − will be a feast for your files!

Overview

Gaufrette

Gaufrette provides a filesystem abstraction layer.

Build Status AppVeyor Status Quality Score Packagist Version Total Downloads Software License Join the chat at Gitter

Why use Gaufrette?

Imagine you have to manage a lot of medias in a PHP project. Lets see how to take this situation in your advantage using Gaufrette.

The filesystem abstraction layer permits you to develop your application without the need to know where all those medias will be stored and how.

Another advantage of this is the possibility to update the files location without any impact on the code apart from the definition of your filesystem. In example, if your project grows up very fast and if your server reaches its limits, you can easily move your medias in an Amazon S3 server or any other solution.

Documentation

Read the official Gaufrette documentation.

Metapackages for adapters

Every maintained adapter now have a dedicated metapackage. You can find the list on packagist. We highly recommend you to use them as they contain their own requirements: you don't need to worry about third-party dependencies to install before using Gaufrette anymore.

Symfony integration

Symfony integration is available through KnpLabs/KnpGaufretteBundle.

Maintainers

Here is the list of dedicated maintainer(s) for every adapter not deprecated. If you don't receive any response to your issue or pull request in a timely manner, ping us:

Adapter Referent
AsyncAws S3 @Nyholm
AwsS3 @NiR-
AzureBlobStorage @NiR-
DoctrineDbal @pedrotroller, @NicolasNSSM
Flysystem @nicolasmure
Ftp @fabschurt
GoogleCloudStorage @AntoineLelaisant
GridFS @NiR-
InMemory
Local
OpenCloud @NiR-
PhpseclibSftp @fabschurt
Zip

For InMemory, Local and Zip adapters everyone in this list is considered as a maintainer.

Development

Requires the latest versions of :

  • docker-ce
  • docker-compose
  1. Create .env file :
$ make dev

and configure it as you want.

  1. Build the php docker image :
$ make build
  1. Install dependencies :
$ make install-deps
  1. Run tests :
$ make tests

You can also use a different php version, simply set the PHP_VERSION env var to any of these values when calling a make target :

See the docker-compose.yml file for more details.

You'll need to clear the previously installed dependencies when switching from a version to an other, to do so, run :

$ make clear-deps
$ PHP_VERSION=<the_version_you_want_to_use> make build install-deps
  1. Apply Coding Standards

You should check for CS violations by using

$ make php-cs-compare

and fix them with

$ make php-cs-fix

Note

This project does not have any stable release yet but we do not want to break BC now.

Comments
  • Could not write the key content

    Could not write the key content

    I get the following error when I try to write an uploaded file my Amazon S3 bucket

    Could not write the "2014/04/24/53596551ee0ec.m4a" key content." at .../vendor/knplabs/gaufrette/src/Gaufrette/Filesystem.php line 113

    opened by jspizziri 13
  • [Feature] Support for multi-container Azure workflow

    [Feature] Support for multi-container Azure workflow

    Currently, the AzureBlobStorage adapter requires a single container name which will be filesystem root, it might try to create it.

    If I'm using a single storage account to hold only one type of asset (say, only images), I'd like to use one container per image (which will hold the original and all the variants), much like for example Azure Media Services does. This also seems to be a recommended way of doing things.

    What could be done here is add an additional flag / mode which would take the storage key and use the part until the first slash, create a container (if it doesn't already exist) and use the rest of the path as key. Ie.

    write('my/image/path.jpeg') // "my" = container, "image/path.jpeg" = key
    

    Some sort of container default creation options should also be provided (for example, access mode), but I think it shouldn't be all that hard.

    Feature 
    opened by dkarlovi 12
  • Cannot use phpseclib\Net\SFTP as SFTP because the name is already in use in ../knplabs/gaufrette/src/Gaufrette/Adapter/PhpseclibSftp.php on line 6

    Cannot use phpseclib\Net\SFTP as SFTP because the name is already in use in ../knplabs/gaufrette/src/Gaufrette/Adapter/PhpseclibSftp.php on line 6

    I get the following error when using Gaufrette in a Symfony 2.4 environment when i do a cac:clear:

    Cannot use phpseclib\Net\SFTP as SFTP because the name is already in use in ../knplabs/gaufrette/src/Gaufrette/Adapter/PhpseclibSftp.php on line 6

    I'm using the following versions:

    knplabs/gaufrette | 0.2.1 knplabs/knp-gaufrette-bundle | 0.2.0

    opened by d3vpunk 12
  • implemented fast listKeys for gridfs

    implemented fast listKeys for gridfs

    as proposed in #118 . Filesystem now checks if adapter has listKeys method (no need to implement it for all adapters, imho, since filesystem/ftp traversing is not subject to optimization), gridfs implements listKeys via MongoRegex.

    I also added a typehint to FunctionTest $filesystem property.

    @l3l0 , please check it this PR complies to your thoughts about Gaufrette. If it's ok, I'll propapbly implement it also for doctrine via LIKE (is also should be applicable to S3 / Rackspace, but I've no posibillity to test that).

    opened by andrewtch 12
  • Initial MogileFS Adapter

    Initial MogileFS Adapter

    Hi again

    My colleague @mtarvainen has now finished an initial version of MogileFS adapter. Would you be interested in pulling that in?

    I know tests are still missing but we're going to make them 'soon'. Anyway, I was told that at least the basic functionality should be ok.

    opened by TomiS 12
  • [streem] stream_wrapper_unregister(): Unable to unregister protocol gaufrette://

    [streem] stream_wrapper_unregister(): Unable to unregister protocol gaufrette://

    Stacktrace (most recent call first):

      File "/home/foobar/vendor/knplabs/gaufrette/src/Gaufrette/StreamWrapper.php", line 72, in handleError
        return @stream_wrapper_unregister($scheme);
      File "/home/foobar/vendor/knplabs/gaufrette/src/Gaufrette/StreamWrapper.php", line 72, in streamWrapperUnregister
        return @stream_wrapper_unregister($scheme);
      File "/home/foobar/vendor/knplabs/gaufrette/src/Gaufrette/StreamWrapper.php", line 48, in register
        static::streamWrapperUnregister($scheme);
      File "/home/foobar/vendor/knplabs/knp-gaufrette-bundle/Knp/Bundle/GaufretteBundle/KnpGaufretteBundle.php", line 25, in boot
        StreamWrapper::register($this->container->getParameter('knp_gaufrette.stream_wrapper.protocol'));
      File "/home/foobar/app/bootstrap.php.cache", line 2190, in boot
        $bundle->boot();
      File "/home/foobar/app/AppKernel.php", line 185, in boot
        parent::boot();
      File "/home/foobar/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php", line 56, in forward
        $this->getKernel()->boot();
      File "/home/foobar/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php", line 430, in fetch
        $response = $this->forward($subRequest, $catch);
      File "/home/foobar/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php", line 330, in lookup
        return $this->fetch($request, $catch);
      File "/home/foobar/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php", line 194, in handle
        $response = $this->lookup($request, $catch);
      File "/home/foobar/web/app.php", line 13, in null
        $response = $kernel->handle($request);
    
    opened by makasim 11
  • Refactoring, metadata and adapter specific files

    Refactoring, metadata and adapter specific files

    Ok, here's a new one. I think I managed to do this with a lot less BCBs, maybe even none.

    Here's what I did:

    • Added File folder that contains storage specific file objects. Some adapters may not need them so they can use File class directly but some adapters definitely benefit from customized File object.
    • Removed metadata related code from adapters as it's a feature of a file (not BCB because it didn't work before)
    • Added get function into adapters for retrieving the file object, altered logic in Filesystem::get() to support this.
    • Changed the meaning of createFile. Now it's purely a factory method for creating a new file object.
    • Added writeFile function into adapters for writing files
    • Added metadata as optional parameter for write function. (I think this really must be here to enable any kind of metadata support for old write function. It does not break BC because it's optional.)
    • Moved all interfaces to root folder from Adapter folder. (This is not mandatory, but I really think it's nice to reserve Adapter folder only for adapters, not interfaces)
    • Changed MetadataSupporter to contain method isMetadataKeyAllowed($metaKey);

    This is how it can be used now:

    //Object-oriented write
    $f = $filesystem->createFile($key);
    $f->setMetadataItem('metaKey1', 'metaValue1');
    $f->setMetadataItem('metaKey2', 'metaValue2');
    $f->setContent($fileContentBytes);
    $f->setName('myfile.jpg'); //human-readable name
    $f = $filesystem->writeFile($f, [$overwrite]);
    
    //Object-oriented get, returns file object
    $g = $filesystem->get($key);
    
    //Procedural write
    $filesystem->write($key, $content, [$overwrite], [$metadata]);
    
    //Procedural read (does not support metadata)
    $filesystem->read($key)
    
    //Delete
    $filesystem->delete($key);
    

    And finally, as before, I only implemented GridFS and Local as a proof of concept. More work has to be done before merging in any case...

    opened by TomiS 11
  • AwsS3 Multipart Uploads

    AwsS3 Multipart Uploads

    This is a modification of AwsS3 adapter to allow multipart uploads when files are bigger than a certain size.

    Size limits / part size are passed as options to the adapter and set to defaults, respectively 5Go and 5Mo. 5Go being the maximum size AWS S3 accepts in a single upload, and 5Mo the minimum part size.

    Limitations : won't work with string content, you have to pass a resource handle otherwise write() will return false. We may use InMemoryStream to bypass this limitation ?

    PHP7.1 fails on docker image, not sure why. May need some help on this.

    opened by MonsieurLanza 10
  • Binary data is corrupted when read from GridFS

    Binary data is corrupted when read from GridFS

    That is happens because Gaufrette\Util\Size::fromContent uses mb_strlen and InMemoryBuffer stream uses not multi-byte string manipulations so the numbers are different in case of binary data.

    Changing mb_strlen to strlen fixed issue but I didn't test it with other adapters.

    bug 
    opened by vkartaviy 10
  • [cache] source rename/write fail

    [cache] source rename/write fail

    There is a serious bug in cache adapter - if source has failed to write or to rename a file (eg. S3 invalid key in my case) following happens:

    • native aws exceptions is suppressed with catch return false
    • return false by source silently ignored
    • cache has been written
    • Filesystem reports write/rename was successful
    • FAIL, file does not exist

    Gaufrette\Adapter\Cache::rename()

    Gaufrette\Adapter\Cache::write()

    opened by jaymecd 9
  • Files direct URL

    Files direct URL

    So in my application the user uploads images and Im using Gaufrette to store it either locally in my staging environment or on S3 in production. i was thinking that there must be a way to access the direct URL for a file. whether it's local, S3, Dropbox ... etc. I know this won't be supported in all adapters but it'd be great if its exists in adapters that can support it.

    opened by ghost 9
  • Add support for php 8.2

    Add support for php 8.2

    See https://github.com/phpspec/phpspec/pull/1435 for a similar update and for the reason why ci isn't successfully yet, as phpspec does't support 8.2 yet.

    opened by xelaris 2
  • Flysysystem V2 and V3

    Flysysystem V2 and V3

    Added class FlysystemV2V3 - can be used on both versions.

    • Much of time spent to fix analizers.
    • Psalm upgraded to 4.30.0 to use new plugin system
    • CI flow divided to test and analyse different versions of flysystem

    Inspired on #650

    opened by dmitryuk 1
  • $file->getContent() return a StreamInterface instead of a String with GoogleCloudStorage adapter

    $file->getContent() return a StreamInterface instead of a String with GoogleCloudStorage adapter

    Hi,

    I use Gaufrette with GoogleCloudStorage adapter in production and local filesystem in development and I observe differences on the returned type of getContent() method of File object.

    getContent calls Filesystem->read() which calls adaptater read() method.

    Returned type of File->getContent() should be a string. But, with GoogleCloudStorage adapter, the read() method return a StreamInterface ($response->getBody()) when Google_Http_Request does not exist (view here).

    I suppose this line should be fixed with $response->getBody()->getContents()

    Thx in advance.

    opened by laurentdabbb 2
  • Add tags support for S3 objects

    Add tags support for S3 objects

    Hello,

    Problem: There is no easy way to add tags to S3 objects during upload :worried:

    Solution: I facilitated tag adding by transforming an array of tags into a query string (format supported by AWS). :smile:

    Ex:

    • Input: ['public' => 'yes', 'private' => 'no']
    • Output: public=yes&private=no

    Can you tag the person who is in charge of AWS S3 ? I can't find him (his account no longer exist). :exclamation:

    @Nyholm

    Have a great day!

    opened by LouisGarret 0
Releases(v0.11.1)
  • v0.11.1(Nov 3, 2022)

    Added

    • gitattributes file to avoid download too much files on install with composer in #679

    Fixed

    • Azure integraton with stream was not working properly, it has been fixed in #683
    Source code(tar.gz)
    Source code(zip)
  • v0.11.0(Oct 14, 2022)

    Added

    • Google Cloud Storage: options to automatically create bucket if not exists
    • Support for PHP 8.0+ 🎉
    • Support for doctrine/dbal 3.x

    Updated

    • Azure seems to have break compatibility, phpstan detected it and it's now fixed (#674)

    Removed

    • Adapter for OpenCloud (#669)
    Source code(tar.gz)
    Source code(zip)
  • v0.10.0(Oct 5, 2020)

  • v0.9.0(Dec 26, 2019)

    New features

    • Add MimeTypeProvider to AzureBlobStorage (#630)

    Fixes

    • Fix docker setup for dev env (#580)
    • Define env vars in .env file only (#615)
    • Add PHP Coding Standard check step on CI (#617)
    • PHPUnit tests enhancement (#627)

    Thank you @nicolasmure, @peter279k and @rgembalik for your contributions!

    Source code(tar.gz)
    Source code(zip)
  • v0.8.3(Jun 6, 2019)

  • v0.8.2(Jun 5, 2019)

    New features

    • Declare a FilesystemMapInterface (#604)
    • Add SizeCalculator support to GridFS (#603)
    • Local Adapter: directory deletion (#610)

    Fixes

    • GridFS : return empty array when object has no metadata (#609)

    Thank you @athos7933, @bsperduto and @nicolasmure for your contributions !

    Source code(tar.gz)
    Source code(zip)
  • v0.8.1(Jan 11, 2019)

  • v0.8.0(Dec 21, 2018)

    New features

    • Implement ChecksumCalculator interface for AzureBlobStorage adapter #594

    Changes

    In #593 :

    • Drop support for EOL php versions (5.6 and 7.0)
    • Minimum requirement is now php 7.1
    • Add support for php 7.3

    Fixes

    • fix opencloud tests #579
    • fix appveyor build #589
    • Fix ini_get() for boolean values #595

    Thank you @andreybolonin, @damijank, @deguif and @nicolasmure for your contributions !

    Source code(tar.gz)
    Source code(zip)
  • v0.7.0(Sep 6, 2018)

    Changes

    • FilesystemMap::set() should expects FilesystemInterface instead of Filesystem #576

    Fixes

    • Add PutObjectAcl in the required permission #566
    • Add php 7.2 to travis matrix #567
    • AWS3 docs fix #570
    • Ensure correct return type from Flysystem adapter "exists" method #572

    Thank you @andreybolonin, @clement-michelet, @jakob-stoeck, @nicolasmure, @teohhanhui, @tristanbes for your contributions !

    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(Mar 26, 2018)

  • v0.5.0(Jan 5, 2018)

    New features

    • Added support for calculated size for Azure Blob Storage #523
    • GridFS Support for Metadata Retrieval after Write #535

    Changes

    • Test case for AwsS3 now inherits common test case #514
    • Run azure tests on appveyor #512
    • Bump PHPUnit to ^5.6.8 #529
    • Use composer's autoload-dev #530
    • Drop HHVM support + sync docker conf with Travis #528
    • Refactoring tests to have more detailed failure messages #542

    Fixes

    • Documentation #510
    • Typos #506, #538
    • Fix incomplete tear down phase for AwsS3Test #516
    • Fix FTP tests + bug in PhpseclibSftp::fetchKeys() #527
    • fix travis build for php 5.6 #543
    • Quickfix for Adapter/AwsS3, check if count() call is allowed #544

    Thank you @andreasschacht, @bsperduto, @carusogabriel, @dawkaa, @gerkestam2, @GrahamCampbell, @Lctrs, @nicolasmure, @NiR- for your contributions !

    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Jun 17, 2017)

    • Following adapters have been deprecated: AclAwareAmazonS3, AmazonS3, Apc, Cache, LazyOpenCloud, Sftp, Dropbox, MogileFS, GoogleCloudStorage (see #482)
    • Improvement of test coverage during CI builds: functional tests for AzureBlobStorage, AwsS3, DoctrineDbal, Ftp, GridFS, OpenCloud and PhpseclibSftp now run on Travis (see #457, #460, #483, #484, #500, #504, #505)
    • Maintained adapters now have metapackage to enforce version of 3rd party libraries, and ease installation process (see #487)
    • Add FilesystemInterface and make current Filesystem implement it (see #492)
    • Drop support for PHP v5.4 and v5.5 (see #503)
    • File:
      • Add rename method to File (see #468)
    • Local adapter:
      • Suppress warning if directory has been created between check and create attempt (see #331)
      • Replace file_exists with is_file, to check if given path exists (see #479)
      • Allow Local adapter mkdir mode to cascade to it's Stream (see #488)
      • Fix phpdocs (see #489)
    • AzureBlobStorage:
      • Add support for multi container mode (see #486)
    • AwsS3 adapter:
      • Add ContentType support to AwsS3 (see #451)
      • Allow aws-sdk-php v2 and v3 to be used (see #457, #462, #475)
      • Provide mime type (see #491)
      • Deprecate AwsS3::getUrl() method, instead use ResolvableFilesystem from gaufrette/extras (see #496)
    • GridFS adapter:
      • Unmaintained mongo extension has been replaced with newer mongodb extension (see #460)
    • GoogleCloudStorage adapter:
      • Fixed missing leading "" before Google_Http_Request (see #471)
    • Ftp adapter:
      • Always ensure target directory exists before renaming (see #476)
      • Don't use FTP_USEPASSVADDRESS before php 5.6.18, and 7.0.0/7.0.1 (see #477, #480, #483)
    • Docs:
      • Add minimum IAM roles for AwsS3 adapter, and recommend to manually create bucket (see #467)

    Contributors: @NiR-, @nicolasmure, @WARrior-Alex, @zyphlar, @AntoineLelaisant, @Shivoham, @richardfullmer, @kcassam, @beebop1032, @dkarlovi.

    Also, we thank @edhgoose and @zyphlar who made patches for deprecated adapters, before those adapters were deprecated, but still did not see their respective work merged in this version.

    Source code(tar.gz)
    Source code(zip)
Owner
KNP Labs
Happy Awesome Developers
KNP Labs
Abstraction for local and remote filesystems

League\Flysystem About Flysystem Flysystem is a file storage library for PHP. It provides one interface to interact with many types of filesystems. Wh

The League of Extraordinary Packages 11.9k Apr 22, 2021
This package used to upload files using laravel-media-library before saving model.

Laravel Media Uploader This package used to upload files using laravel-media-library before saving model. In this package all uploaded media will be p

Ahmed Fathy 312 Dec 12, 2022
FileNamingResolver - A lightweight library which helps to resolve a file/directory naming of uploaded files using various naming strategies

FileNamingResolver - A lightweight library which helps to resolve a file/directory naming of uploaded files using various naming strategies

Victor Bocharsky 111 May 19, 2022
Gotipath Storage is a file storage library for PHP. It provides one interface to interact with FTP/SFTP.

Gotipath Storage is a file storage library for PHP. It provides one interface to interact with FTP/SFTP. When you use this package, you're protected from vendor lock-in, That mean you can connect to any FTP/SFTP storage. Also it's comes with base URL option to connect Gotipath CDN.

Gotipath 2 Nov 3, 2021
PHPProject is a library written in pure PHP that provides a set of classes to write to different project management file formats

PHPProject PHPProject is a library written in pure PHP that provides a set of classes to write to different project management file formats, i.e. Micr

PHPOffice 192 Dec 17, 2022
PHP runtime & extensions header files for PhpStorm

phpstorm-stubs STUBS are normal, syntactically correct PHP files that contain function & class signatures, constant definitions, etc. for all built-in

JetBrains 1.2k Dec 25, 2022
This small PHP package assists in the loading and parsing of VTT files.

VTT Transcriptions This small PHP package assists in the loading and parsing of VTT files. Usage use Laracasts\Transcriptions\Transcription; $transcr

Laracasts 52 Nov 28, 2022
ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build parse trees and also generates a listener interface (or visitor) that makes it easy to respond to the recognition of phrases of interest.

Antlr Project 13.6k Jan 6, 2023
Tailwind plugin to generate purge-safe.txt files

Tailwind plugin to generate safelist.txt files With tailwind-safelist-generator, you can generate a safelist.txt file for your theme based on a set of

Spatie 89 Dec 23, 2022
Associate files with Eloquent models

Associate files with Eloquent models This package can associate all sorts of files with Eloquent models. It provides a simple API to work with. To lea

Spatie 5.2k Jan 4, 2023
A python program to cut longer MP3 files (i.e. recordings of several songs) into the individual tracks.

I'm writing a python script to cut longer MP3 files (i.e. recordings of several songs) into the individual tracks called ReCut. So far there are two

Dönerspiess 1 Oct 27, 2021
A Flysystem proxy adapter that enables compression and encryption of files and streams on the fly

Slam / flysystem-compress-and-encrypt-proxy Compress and Encrypt files and streams before saving them to the final Flysystem destination. Installation

Filippo Tessarotto 27 Jun 4, 2022
FileGator - a free, open-source, self-hosted web application for managing files and folders.

FileGator - Powerful Multi-User File Manager FileGator is a free, open-source, self-hosted web application for managing files and folders. You can man

FileGator 1.3k Jan 3, 2023
A PHP library to deal with all those media services around, parsing their URLs and displaying their audios/videos.

MediaEmbed A utility library that generates HTML embed tags for audio or video located on a given URL. It also parses and validates given media URLs.

Mark Sch. 165 Nov 10, 2022
Upload File Library For PHP ( Simple & Easy User )

Upload File Library For Backend/ServerSide PHP ( Simple & Easy For Use ), Support Multiple Upload

Lamhot Simamora 1 Oct 12, 2021
The Hoa\Mime library.

Hoa is a modular, extensible and structured set of PHP libraries. Moreover, Hoa aims at being a bridge between industrial and research worlds. Hoa\Mim

Hoa 100 Nov 20, 2022
☁️ Nextcloud server, a safe home for all your data

Nextcloud Server ☁ A safe home for all your data. Why is this so awesome? ?? ?? Access your Data You can store your files, contacts, calendars and mor

Nextcloud 21.1k Dec 31, 2022
🌩支持多家云存储的云盘系统 (A project helps you build your own cloud in minutes)

Cloudreve 支持多家云存储驱动的公有云文件系统. 演示站 • 讨论社区 • 文档 • 下载 • Telegram 群组 • 许可证 ✨ 特性 ☁️ 支持本机、从机、七牛、阿里云 OSS、腾讯云 COS、又拍云、OneDrive (包括世纪互联版) 作为存储端 ?? 上传/下载 支持客户端直传

Cloudreve 17k Jan 7, 2023
An object oriented PHP driver for FFMpeg binary

php-ffmpeg An Object-Oriented library to convert video/audio files with FFmpeg / AVConv. Check another amazing repo: PHP FFMpeg extras, you will find

null 4.4k Jan 2, 2023