stat.us
stat.us

Reputation: 105

Where is the File::put() stored in Laravel?

I have a question relating to Laravel, where is the File::put() stored in Laravel?

I have checked inside storage/app/public and the content isn't there.

Upvotes: 9

Views: 25827

Answers (4)

Yousef Altaf
Yousef Altaf

Reputation: 2763

Another way you can do this, and you can specify the file_name and the path of your file. Is to use storeAs

so you will end-up with something like this

$file = $request->file('file');    
// Generate a file name with extension
$fileName = 'profile-'.time().'.'.$file->getClientOriginalExtension();

// Save the file
$path = $file->storeAs('files', $fileName);

dd($path);

#output

"files/profile-1564586486.jpg"

Upvotes: 0

to make sure the location you can use the functions

  • public_path ()
  • storage_path ()
  • app_path ()

ex:

File::put(public_path('uploads'), $data);

Upvotes: 3

Vision Coderz
Vision Coderz

Reputation: 8078

File::put store in public folder

for example .In this case file.txt will be created in public folder

File::put('file.txt', 'contents is written inside file.txt');

Also you can use Storage class

Storage::put( 'file.txt','contents is written inside file.txt' );

This will create file inside storage\app

Upvotes: 7

Amit Gupta
Amit Gupta

Reputation: 17658

To store files in folder storage/app, you must use Storage class as:

Storage::disk('local')->put('file.txt', 'Contents');

then it would store a file in storage/app/file.txt.

Docs

Upvotes: 8

Related Questions