I have created a function which stores file path in database and stores the file in public/uploads/release folder. Here is my Controller:
$reference = $request->get('reference');
$uploads = array();
if($files = $request->file('uploads'))
{
foreach ($files as $file) {
$name = $file->getClientOriginalName();
$file->move('uploads/release', $name);
$uploads[] = $name;
}
Here I am storing file in public/uploads/release folder, but now I want to create a folder dynamically every time a file is uploaded, and the folder must be the value from the $reference variable. e.g: reference is 'ABC123'. Then the file must be automatically stored in public/uploads/release/ABC123 folder.
You can use File Class in laravel
use Illuminate\Support\Facades\File;
$path = public_path().'/uploads/release/'.$request->get('reference');
if (! File::exists($path)) {
File::makeDirectory($path);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With