Balaji P
Balaji P

Reputation: 21

How to create a folder in codeigniter

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.

Upvotes: 1

Views: 1518

Answers (2)

Madhuri Patel
Madhuri Patel

Reputation: 1270

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.

Upvotes: 1

Ashwani Singh
Ashwani Singh

Reputation: 159

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

Upvotes: 2

Related Questions