Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

how to save file in storage folder in laravel

//first run this command to generate symbolic link
php artisan storage:link

//then in controller function
$fileTemp = $request->file('file');
if($fileTemp->isValid()){
  $fileExtension = $fileTemp->getClientOriginalExtension();
  $fileName = Str::random(4). '.'. $fileExtension;
  $path = $fileTemp->storeAs(
  	'public/documents', $fileName
  );
}
//above code will save your file in 'storage/app/public/documents' location
//and using symbolic link we can access this file here 'public/storage/documents'

//Now Open or download file in blade template
<a href="{{url(Storage::url($document['file']))}}">Open/Download</a>
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #save #file #storage #folder #laravel
ADD COMMENT
Topic
Name
9+5 =