Questions tagged [laravel-filesystem]

Flysystem, introduced in Laravel 5.0, is a file system abstraction layer that allows local file systems and cloud-based storage services provided by Amazon S3 and Rackspace Cloud to be used transparently and in the same way.

Laravel provides a wonderful filesystem abstraction thanks to the Flysystem PHP package by Frank de Jonge. The Laravel Flysystem integration provides simple to use drivers for working with local filesystems, Amazon S3, and Rackspace Cloud Storage. Even better, it's amazingly simple to switch between these storage options as the API remains the same for each system!

Configuration

The filesystem configuration file is located at config/filesystems.php. Within this file you may configure all of your "disks". Each disk represents a particular storage driver and storage location. Example configurations for each supported driver is included in the configuration file. So, simply modify the configuration to reflect your storage preferences and credentials!

Before using the S3 or Rackspace drivers, you will need to install the appropriate package via Composer:

Amazon S3: league/flysystem-aws-s3-v2 ~1.0
Rackspace: league/flysystem-rackspace ~1.0

Of course, you may configure as many disks as you like, and may even have multiple disks that use the same driver.

When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory. Therefore, the following method would store a file in storage/app/file.txt:

Storage::disk('local')->put('file.txt', 'Contents');

Reference

105 questions
36
votes
6 answers

Laravel 5.3 Storage::put creates a directory with the file name

I'm using Laravel's file storage functionality to save a file: public function dataPost(Request $request) { $fileInForm = 'doc'; if ($request->hasFile($fileInForm)) { $file = $request->file($fileInForm); if…
zundi
  • 2,361
  • 1
  • 28
  • 45
21
votes
5 answers

Image Validation in Laravel 5 Intervention

I have installed intervention in Laravel 5.1 and I am using the image upload and resize something like this: Route::post('/upload', function() { Image::make(Input::file('photo'))->resize(300, 200)->save('foo.jpg'); }); What I dont understand is,…
Neel
  • 9,352
  • 23
  • 87
  • 128
20
votes
3 answers

Laravel Impossible to Create Root Directory

I've checked out the other posts about this, mine seems to be unique for some reason Essentially what I'm trying to do is store uploaded photos in the public directory for easy access, however when I store them I'm trying to store them in a user…
Zach Handley
  • 914
  • 1
  • 12
  • 25
18
votes
6 answers

Laravel 5: How do you copy a local file to Amazon S3?

I'm writing code in Laravel 5 to periodically backup a MySQL database. My code thus far looks like this: $filename = 'database_backup_'.date('G_a_m_d_y').'.sql'; $destination = storage_path() . '/backups/'; $database =…
clone45
  • 8,952
  • 6
  • 35
  • 43
15
votes
3 answers

Laravel File Storage: How to store (decoded) base64 image?

How to store base64 image using the Laravel's filesytem (File Storage) methods? For example, I can decode base64 image like this: base64_decode($encoded_image); but all of the Laravel's methods for storing files can accept either a…
PeraMika
  • 3,539
  • 9
  • 38
  • 63
6
votes
3 answers

Laravel Symbolic Link not working

I have some problems creating a symbolic link with laravel to access files that are in my storage I am storing my files in storage\app\public I used the php artisan command to create the link php artisan storage: link The [public/storage] directory…
Ndroid21
  • 400
  • 1
  • 8
  • 19
6
votes
0 answers

How to move files from local filessytem to cloud filesystem In laravel 5

I have files in my local storage public/images/users and I want to move these files to cloud storage AWS S3 using the Laravel filesystem. Route::get('upload-local-files-to-s3', function() { $documentFiles =…
Waqas Mehmood
  • 199
  • 3
  • 17
6
votes
4 answers

Laravel check if storage exists is not working

I'm trying to check if file already exist in the storage by if(Storage::exists($request->file_name)): dd(var_dump("it did exist")); else: dd(var_dump("it did not exist")); endif but it always return a string "it did exist" even though the…
Juliver Galleto
  • 8,831
  • 27
  • 86
  • 164
6
votes
2 answers

How to use google cloud storage as Laravel 5 filesystem?

I'm developing an application that lets my users upload files, and I've made it works with "local" disk using filesystem feature, but now I want to migrate and use google Google Cloud Storage for it. It has been a lot difficult to find some useful…
4
votes
1 answer

League\\Flysystem\\AwsS3v3\\AwsS3Adapter::__construct(): Argument #1 ($client) must be of type Aws\\S3Client, Aws\\S3\\S3Client given

I have installed the s3 flysystem package by running the following composer command in my Laravel 8 project composer require --with-all-dependencies league/flysystem-aws-s3-v3 "^1.0" and tried to store a file from the request as $imageName =…
4
votes
1 answer

How to get non image recently uploaded temp file name in Laravel Livewire

I am using Livewire to upload a non image file. When uploading the file, Livewire automatically generates a long name for the temporary file and stores it in the default livewire-tmp directory. I want to know how to retrieve the recently uploaded…
Pathros
  • 10,042
  • 20
  • 90
  • 156
4
votes
2 answers

Laravel move files from one disk to another disk - using `Storage`

I have two disks defined in my filesystems.php config file: 'd1' => [ 'driver' => 'local', 'root' => storage_path('app/d1'), ], 'd2' => [ 'driver' => 'local', 'root' => storage_path('app/d2'), ], These disk could also be Amazon S3…
brnd0
  • 338
  • 6
  • 15
4
votes
1 answer

How to Download all Files listed in a directory from SFTP in laravel 5.6

I am new to laravel. I am making an application in which I check a directory that is being served on an SFTP. By looking into the documentation I was successfully able to list all the file names inside a directory hosted on that SFTP. My next goal…
umair.ashfr
  • 1,171
  • 13
  • 32
4
votes
1 answer

how to read .txt file which contains string to an array in laravel

I would like to read .txt file contains string and convert it to an array, for better display i copy my string in .txt here. Scan Date,Date,Time,PIN,Number,Name,Position,Department,Office,Verification,I/O,Workcode,SN,Machine 02-05-2017…
CodeGG
  • 43
  • 1
  • 5
3
votes
2 answers

Laravel php delete a directory (folder) via sftp

I am trying to delete a folder on my server via sftp. I am using php 7.4.13 and laravel 7.30.4 I have set up my sftp drive and everything (upload, delete files, create directory) works fine. But the only problem is that I could not delete a…
eva li
  • 31
  • 3
1
2 3 4 5 6 7