Title: How to create a folder in codeigniter
Tags: php;directory
Question: I am creating a folder with mkdir() in php but I don't know how to create a folder in CodeIgniter. Anyone can tell me how to create that with mkdir() function.

Comment: CodeIgniter _is_ PHP. It's just a framework.

Comment: Does this answer your question? [Codeigniter make directory if not exist](https://stackoverflow.com/questions/16435597/codeigniter-make-directory-if-not-exist)

Comment: follow this link https://stackoverflow.com/a/18217147/10430605

Comment: follow the given link.
https://stackoverflow.com/a/58428797/7327310
perhaps, it will help you.

Comment: @NikhileshAgrawal Actually that's a PHP code...I need to Codeigniter customized code

Here is the accepted answer: You can create a folder using ```mkdir()``` like this ```mkdir($path,0777,true)```.
For example if your codeigniter project structure is like ```C:\xampp\htdocs\Prjects Folder\...``` and you want to create a folder inside assets folder (i.e for images you want to create an Image folder) then you can create it like this.

```if(!is_dir('././assets/images') )
        {
            mkdir('././assets/images',0777,TRUE);
        }
```

Note: To know more about mkdir() check this link https://www.php.net/manual/en/function.mkdir.php


Here is another answer: First add your path using ```realpath``` function which gives you absolute path and then use ```mkdir``` to create folder.

Example: 
Here i am store one image within folder because it is not exist so i have to create folder first then i have to add.

```$path = realpath(APPPATH . 'images/test.jpg');

if(!file_exists($path))
{
   mkdir($path,0777,TRUE);
}
```

Note: PHP or Codeigniter, we can follow same process to create directory.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:01/29/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><directory>', 'Title': 'How to create a folder in codeigniter', 'ViewCount': 817, 'id': 59961272, 'user_AboutMe': None, 'user_AccountId': 17471109.0, 'user_DisplayName': 'Balaji P', 'user_Reputation': 11.0, 'user_Views': 17.0, 'user_id': 12666895.0}}