pandiyan's avatar

laravel mkdir

Hi ,i need to upload images in my project ,so i use this mkdir("/images') code for create folder, but i don't know where the folder is created in my project. i need to know that images folder location

0 likes
4 replies
bobbybouwmann's avatar
Level 88

mkdir is a server command so it will create the folder based on the path of the server. In your case /images will be created at the root of your server, not the root of your project.

When uploading files with Laravel, it will automatically create the correct directory for you. So in most cases, this is not needed.

If you want to create a directory in your project you should use this instead

mkdir(base_path('images')); // /www/project/images

mkdir(public_path('images')); // /www/project/public/images

This will create the images directory in the root or the public directory of your project.

boyjarv's avatar

ok I just tried:

$jsongFile = time() . '_file.json';

        $path = public_path('imagez/john');
        if ( ! File::exists($path) ) { File::makeDirectory($path,0777,true); }
        
        file_put_contents($path.$jsongFile, $course->toJson());
        return Response::download(public_path('/upload/json/'.$jsongFile));

I'm getting:

The file "/Users/me/Documents/laravel/btw22mongo/public/upload/json/1673562124_file.json" does not exist

boyjarv's avatar

argh please help, now I'm getting: "The file "/Users/me/Documents/laravel/btw22mongo/public/upload/json/1673565607_file.json" does not exist",

$jsonFile = time() . '_file.json';

        $path = 'imagez';
        if ( ! File::exists(public_path($path)) ) {
            mkdir($path,0777,true);
            file_put_contents(public_path($jsonFile), $course->toJson());
        }

a folder imagez has been created and a file 1673565607_file.json has also been created but the file is not in that folder?!

Please or to participate in this conversation.