Is there any differences between File and Storage facades in laravel 5.2 ?
it seems they both use the same contract.i see no documentation for File in laravel documentation.
if they are different how may interact with each other?
Is there any differences between File and Storage facades in laravel 5.2 ?
it seems they both use the same contract.i see no documentation for File in laravel documentation.
if they are different how may interact with each other?
The File Facade just contains some primitive methods that work only with absolute path or relative to your script:
\File::makeDirectory('/home/www/myProject/storage/app/uploads/14214');\File::copy('/home/www/myProject/storage/app/uploads/14214/test.json', '/home/www/myProject/storage/app/uploads/99999/test.json');The Storage Facade contains a set of complex methods and is a wrapper for other 3rd party tools.
The first advantage is, you can use relative path to a folder:
Storage::makeDirectory('uploads/14214');Storage::copy('uploads/14214/test.json', 'uploads/99999/test.json');you may change the default folder /storage/app in config/filesystems.php or create other disks that you may call with Storage::disk('specialxyz')->copy(...).
Also you can save raw file contents into a file like this:
Storage::put('file.jpg', $contents);And my favorite, its very easy to upload user files by
$path = Storage::putFile('avatars', $request->file('avatar'));
or
$path = $request->file('avatar')->store('avatars');
By default, the store method will generate a unique ID to serve as the file name. The file's extension will be determined by examining the file's MIME type. The path to the file will be returned by the store method so you can store the path, including the generated file name, in your database.