Answers for "save file laravel"

PHP
0

laravel storage get file path

use Illuminate\Support\Facades\Storage;

$path = Storage::path('file.jpg');
Posted by: Guest on October-17-2020
0

create file in laravel

namespace App\Http\Controllers;
use File;
class FileController extends Controller
{
    public function downloadJSONFile(){
      $data = json_encode(['Element 1','Element 2','Element 3','Element 4','Element 5']);
      $file = time() .rand(). '_file.json';
      $destinationPath=public_path()."/upload/";
      if (!is_dir($destinationPath)) {  mkdir($destinationPath,0777,true);  }
      File::put($destinationPath.$file,$data);
      return response()->download($destinationPath.$file);
    }
}
Posted by: Guest on May-10-2021
0

laravel store file

$path = $request->file('avatar')->store(
    'avatars', 'public'
);
Posted by: Guest on December-05-2020

Browse Popular Code Answers by Language