I have a directory path '/uploads/files'. When a user registers, I'm trying to append their user_id to the end of the path to make it 'uploads/files/user_id' so that each user has their own upload folder to upload to. I'm using Laravel, and my current code looks like this...
mkdir("uploads/files/" . Auth::user()->id);
Is this the proper way to create a new folder? I've been playing around with it a bunch of different ways and can't seem to get anything to work.
mkdir
is the way to go. However you need to keep in mind that linux permission must be set correctly for this to work. Make sure you have writing rights. You can check with is_writable($dirPath)
. Set the permission to 755
or whatever you think works best for your application.
You can also use linux syntax like below... it's handy for more complex operations.
$path = '/uploads/files/user_id_dir';
shell_exec("mkdir -p $path");