Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mkdir and subfolders

Tags:

php

Hi i'm not able to test this on the server, but if folder date(Y) does not exist, is this coding write for it to be created. or do I have to do mkdir("/o_rec/" . date(Y) by itself first? Will supporting subfolders all be created if not present

if(!is_dir("/o_rec/" . date(Y) . "/" . date(m) . "/" . $id)) {
     mkdir("/o_rec/" . date(Y) . "/" . date(m) . "/" . $id);
}
like image 202
acctman Avatar asked Nov 18 '10 10:11

acctman


People also ask

How do I create a subfolder in mkdir?

Building a structure with multiple subdirectories using mkdir requires adding the -p option. This makes sure that mkdir adds any missing parent directories in the process. Use ls -R to show the recursive directory tree.

Can mkdir create nested directories?

We can use the -p option with the mkdir command to create a directory inside another directory. We can create nested directories without using this option too, but suppose we want to create a directory dataset inside a directory project and if there's no directory named project, then an error will occur.

How do I make multiple folders in one mkdir command?

The four subdirectories are created under the htg directory and then the two subdirectories, new and rewrites, are created under the articles subdirectory. It's that easy. You can also combine the mkdir command with the cd command to make a directory and change to it with one command.

What is subfolder and folder?

A subfolder is a folder stored inside another folder. Subfolders help you organize your files more completely. Each subfolder should be used to store files related to each other. For example, you might have one folder for files related to a job search. Add subfolders for all of your files, such as family-related files.


2 Answers

bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )

you would need to set recursive to true

like image 64
ajreal Avatar answered Sep 30 '22 14:09

ajreal


You should use set the "recursive" flag on you mkdir call to have it make the entire path you want.

http://php.net/manual/en/function.mkdir.php

Be advised that a google search makes it looks like there may be an existing bug, depending on your php version.

like image 31
Patrick Farrell Avatar answered Sep 30 '22 15:09

Patrick Farrell