Reputation: 41
I have a user system where, when you register for an account, it's supposed to automatically create a new folder for you.
I've placed something along the lines of mkdir('./upload/' . $this->session->userdata('id'), 0, true) in my Register controller but to no avail.
Does anybody know how to get it to work?
Upvotes: 4
Views: 10407
Reputation:
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!
Upvotes: 0
Reputation: 100175
Did you try setting permission while creating folder, like doing :
mkdir('./upload/' . $this->session->userdata('id'), 0777);
Upvotes: 4
Reputation:
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.
Upvotes: 2