How to use ftp with laravel 5?

Benubird picture Benubird · Jul 28, 2017 · Viewed 11.2k times · Source

The file Storage section of the laravel docs shows an example FTP config, but it doesn't explain how to use it. Can someone give an example of how to make laravel use an ftp connection in addition to a disk connection?

Answer

Joe picture Joe · Jul 28, 2017

https://laravel.com/docs/5.4/filesystem

The beauty of the Laravel filesystem (and a lot of Laravel) is that the commands are "driver agnostic". This means that you define which "driver" (in your case FTP) to use, and configure it, and then all of the comands are the same.

So to upload a file to your ftp filesystem, you would do something like:

Storage::disk('ftp')->put('avatars/1', $fileContents);

The paramenter for the ::disk method above defines which "disk" Laravel should use, so if you had S3 set up, you would do this instead:

Storage::disk('s3')->put('avatars/1', $fileContents);