T
T
Tarasovych2017-04-17 17:31:11
Laravel
Tarasovych, 2017-04-17 17:31:11

How to create or check if a folder exists before uploading a file?

Controller:

if($request->hasFile('image'))
{
            $image = $request->file('image');
            $filename = time().'.'.$image->getClientOriginalExtension();
            $location = public_path('files/images/blog/' . $filename);
            \Illuminate\Support\Facades\File::makeDirectory($location);
            Image::make($image)->save($location);
}

Mistakemkdir(): No such file or directory

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-04-17
@webinar

check: www.php.su/file_exists
create: php.net/manual/ru/function.mkdir.php

U
UksusoFF, 2017-04-17
@UksusoFF

https://laravel.com/docs/5.4/filesystem#file-uploads and Storage::makeDirectory($directory); will do everything for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question