d_4dinkey
d_4dinkey

Reputation: 741

Setup the file directories and file permissions in codeigniter 2.1.4

I am using codeigniter version 2.1.4 for my website. I am trying to create directories whenever a user signs up for an account.

For example: After recieving the success status from a signup function.

//Right after the signup, i am trying to do this to create directories. 

  $dirname = base_url().'uploads/'.$this->input->post('username').'/';

  if(!is_dir($dirname)){
    echo 'not a directory';
    mkdir(base_url().'uploads/'.$this->input->post('username').'/');
  }else{
    echo 'is directory: '.$dirname;
  }

Would be great if someone helps me out so that i can set the file permissions successfully. Thanks.

Upvotes: 1

Views: 438

Answers (1)

Twisted1919
Twisted1919

Reputation: 2499

I believe you are after:

$userFolder = str_replace(array('../', '..'), '', $this->input->post('username'));
$dirname = FCPATH.'uploads/'.$userFolder.'/';

if (!file_exists($dirname) || !is_dir($dirname)){
    echo 'not a directory';
    mkdir($dirname, 0777, true);
} else {
    echo 'is directory: '.$dirname;
}

Upvotes: 2

Related Questions