I'm trying to create a folder structure which has multi level sub folders. For example, I want to create a folder structure like 'Fruits/Edible/Seedless'. I tried it with mkdir($path) but it could not done. I tried with single level folder, its created. Help me to create this subfolder structure.
You must connect PHP to the MySQL database with its credentials. After that start writing code for creating a multilevel category File Name – database.php 3. Create a Multilevel category Using PHP To create a multilevel category, you have to declare the following PHP functions –
For this, we have multidimensional arrays. A multidimensional array is an array containing one or more arrays. PHP supports multidimensional arrays that are two, three, four, five, or more levels deep. However, arrays more than three levels deep are hard to manage for most people.
Each PHP file can belong to a single namespace, and you tell that by writing the following code at the beginning. You can also nest namespaces into one another, like namespace MyNamespace\SubNamespace. Then, you can use the same class names in different namespaces, they will still remain different classes with no conflict.
With this PHP project structure, your PHP application will be much more maintainable. One additional thing, not strictly related to the PHP project structure, is the naming convention. You can have snake casing, camel casing and so on. You can put curly brackets on the same line of the if, or on the next line.
Try using the recursive flag for mkdir($path, $chmod, $recursive)
<?php
mkdir($path, 0, true);
?>
From php.net= recursive Allows the creation of nested directories specified in the pathname. Defaults to FALSE.
bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )
See specifically: bool $recursive = false
.
http://php.net/manual/en/function.mkdir.php
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