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
3
votes
2 answers

Symbolic link from public/storage to storage/app/public still makes the files in the storage directory accessible from the web

What I have done When I researched about storing files in laravel. I came across two approaches. Storing the assets directly inside the public folder. Creating a symbolic link from public/storage to storage/app/public When I researched about which…
3
votes
1 answer

Custom storage path per model

I'm implementing an email handling system where I want to save the original email and all its attachments to a path. For example - mail-data/123456/5 Where 123456 is the parent ID and 5 is the child ID. In filesystems.php I've created a custom disk…
Chris
  • 1,939
  • 1
  • 19
  • 38
3
votes
3 answers

Laravel 5.5 read a file from the local disk

I am trying to import a csv file with Laravel 5.5 from the local file location. For some reason it can't find the file on my computer however the path is correct. $fileLocation = $request->file('file')->store('csv'); $importFile =…
3
votes
1 answer

storing files to aws s3 using laravel

Please give me an example to store files to AWS S3 in laravel 5.5. I already configured filesystem file with AWS credentials. I saw the function Storage::put('file.jpg', $contents); but don't know what the second parameter is the contents of…
3
votes
2 answers

Laravel Flysystem & Rackspace CRON uploads fail with 401 while on-demand uploads work

Our system generates various invoices every hour and uploads those to the cloud. Also it is possible to create the invoice on demand by clicking a button on our frontend. When manually requesting to create the said invoice then it never fails to…
Artur K.
  • 3,263
  • 3
  • 38
  • 54
2
votes
2 answers

Download file from backend laravel using vue as frontend

I have created controller in Laravel which contains following code $doc = Document::find($id); if (Storage::disk('local')->exists($doc->path)) { return Storage::disk('local')->get($doc->path); } In my frontend I'm using javascript to…
Ankit.Z
  • 740
  • 8
  • 20
2
votes
0 answers

How to prevent the file from public on Digital Ocean Space?

Hi everyone I stuck on Digital Ocean that I want to prevent my file from the public. First of all. I set the .env file like this DO_SPACES_KEY= THE KEY DO_SPACES_SECRET= THE…
2
votes
0 answers

Laravel How To use another server as file storage

I am using Laravel 7.6: I have two Laravel projects in each server (server is normal server. Neither AWS nor Digital Ocean, Just dedicated server). Project1 is in server1. Project2 is in server2. My question is: How can I do CRUD from Project1 To…
LoveCoding
  • 1,121
  • 2
  • 12
  • 33
2
votes
1 answer

How to return image in Laravel 6?

I have this code: public function showImage($id) { $item = File::find($id); return response()->file($item->file_name_and_path); } $item->file_name_and_path contains the following: files/2020/04/29/myfile.jpeg Now I always get a…
netdjw
  • 5,419
  • 21
  • 88
  • 162
2
votes
2 answers

How to serve the data returned from laravel Storage::disk('private')->get($file) as PDF

My question is about the problem in link below : Understanding file storage and protecting contents Laravel 5 I need to use the same method mentioned in above example but instead of an image I need to provide a download link for PDF file or a link…
2
votes
0 answers

How can I use Laravel's Storage to download files from a remote SFTP server?

I'm writing an artisan command in Laravel 5.5. There are files in an AWS EC2 instance and all within the same folder, my command needs to download all those files into a local storage/folder. I went through the Laravel's documentation but couldn't…
Bahman.A
  • 1,166
  • 4
  • 18
  • 33
2
votes
0 answers

Intervention Image can't write to storage_path

I want to store uploaded image to storage_path (storage/app/images/users) and not public_path (public/images/users) in my Laravel application. My filesystem configuration is as follows: 'disks' => [ 'local' => [ 'driver' => 'local', …
Josh
  • 1,660
  • 5
  • 33
  • 55
2
votes
1 answer

Laravel file manager Dynamic base_directory

I using unisharp's laravel file manager. it works great and i am in love with the flexibility it has. However, I need to users to store their files in their respective folders. i am able to do this by changing user_field in conf file. What i am not…
Max Ahmed
  • 135
  • 1
  • 8
2
votes
0 answers

Validate a file from Storage Laravel 5.3

Scenario I am working on a project where csv files are uploaded and processed. Following is a use case: Task 1: User A can upload data.csv using interface or ftp Task 2: User B selects a certain csv file from UI and process it Problem File upload…
PseudoAj
  • 5,234
  • 2
  • 17
  • 37
2
votes
1 answer

Laravel Storage returns: mkdir(): File exists

When I'll try to check if a file exists in Laravel 5.1 I am always getting this error: ErrorException in Local.php line 95: mkdir(): File exists I don't know what could here be wrong, I want to check if a file exists or not with: $exists =…
derdida
  • 14,784
  • 16
  • 90
  • 139