php-laravelHow do I upload a file using PHP and Laravel?
To upload a file using PHP and Laravel, you can use the request()->file('file') method. This method takes the name of the file from the form field and stores it in the $file variable.
Example code
$file = request()->file('file');
The file can then be stored using the Storage::put() method. This method takes two parameters, the first being the path to the file and the second being the file itself.
Example code
Storage::put('file.txt', $file);
The file can also be moved to a different location using the Storage::move() method. This method takes three parameters, the first being the path to the file, the second being the new path and the third being the file itself.
Example code
Storage::move('file.txt', 'new-file.txt', $file);
Helpful links
More of Php Laravel
- How can I use PHP and Laravel together?
- How can I find PHP Laravel jobs?
- How do I use Enum in Laravel with PHP?
- How do I decide between using PHP Laravel and Yii for my software development project?
- How can I use Xdebug to debug a Laravel application written in PHP?
- How can I configure Nginx to work with Laravel on a PHP server?
- How can I use PHP XLSXWriter with Laravel?
- How can I use XAMPP to develop a project in Laravel with PHP?
- How do the development frameworks PHP Laravel and Python Django compare?
- How can I use PHP Laravel to create a Wikipedia page?
See more codes...