Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to save my files with Storage::put($file, $content) in laravel 5.2

Just a simple doubts-

i'm trying to store my image and video file on storage using Storage facade. but i'm confused because i'm unable to store that file on storage folder. i'm using intervention image package and when i just try to save my modified $file

Storage::put($file); it's throwing error that 2 argument missing etc.

i searched everywhere on the net regarding this issue and i found

Storage::put($file , $content) now what is $content in this case when i'm trying just save an image to my folder ? please give me example-

and one more thing

How do i return a full path of that file which can be accessible from different domain. i'm building an API :)

Thanks for the help in advance

like image 550
Rahul Avatar asked Jul 06 '16 20:07

Rahul


1 Answers

What disk your using 'public', 'local' basically where your storing it?

   \Storage::disk('local')->put($file_name, $the_file);

The disk settings can be view in the config/filesystems.php file.

Also the $content is the actually item/file you want to save. Here is an example of what ive done recently..

   // the $image is from $request->file('file');
   $thefile = \File::get($image);
   $file_name = $title->slug . '-' . $year . '.jpg';
    \Storage::disk('local')->put($file_name, $thefile);
like image 50
Simon Davies Avatar answered Sep 28 '22 06:09

Simon Davies