How do I get CodeIgniter to create new folders? How do I get CodeIgniter to create new folders? codeigniter codeigniter

How do I get CodeIgniter to create new folders?


Did you try setting permission while creating folder, like doing :

mkdir('./upload/' . $this->session->userdata('id'), 0777);


Did you setup the correct permissions? Codeigniter, or any other PHP script, won't be able to create any files or directories when they're not allowed due to incorrect CHMOD values. A value of either 755 or 775 should do in most cases. You can change these values using either the command line or using an FTP application (most applications can do that). Also be sure that either the owner or group is set to the same user as your webserver is running (www-data in most cases).

Examples:

chmod -R 775 /var/www/username/codeigniterapp.com/some_dir

You can change the group/user with the "chown" command:

chown -R www-data:someuser /var/www/username/codeigniterapp.com/some_dir

Note that the -R flag tells the command to execute itself recursively. If you only want to change the permissions of the top level directory you can simply remove the -R flag.


I have a wild idea, but might be the perfect solution to your problem. It set the permission also correctly from the start. My idea is to use CodeIngniter's FTP Class, then to create the directory with FTP.

$this->ftp->mkdir('/public_html/profile_pictures/username/', DIR_WRITE_MODE);

Then follow up with code below to make the permission value to 777.

$this->ftp->chmod('/public_html/profile_pictures/username/', DIR_WRITE_MODE);

Then to delete the directory is also very easy.

$this->ftp->delete_dir('/public_html/profile_pictures/username/')

Like I said very wild idea!