How can I save file from external url Laravel public directory
20,350
Solution 1
create an img folder in public path and :
$image = file_get_contents("https://logos-download.com/wp-content/uploads/2016/09/Laravel_logo.png");
file_put_contents(public_path('img/a.png'), $image);
Solution 2
use File like below
use Illuminate\Support\Facades\File;
and then
File::put(public_path( 'ANY FILE YOU WANT' ));
example:
File::put( public_path( 'js/a.js'), ' CONTENT ');
Comments
-
Siddharth almost 2 years
I wanted to save a file from External Url which would have any kind of file like say "jpg, png, mp4 etc"
I want to save it in the public directory of Laravel App. How could I do that? Any help will be highly appreciated.
I tried the following thing, but it's saving file in my storage folder:
Storage::put($name, $contents);
Thanks