Codeigniter Tank Auth add folder upon registration

2019-08-29 10:23发布

I have downloaded Tank Auth and am trying to create a folder when the user registers. I have edited the create_user() function in the users.php model like so but the folder does not get created. I am on Windows 7 so I thought maybe it was a permission thing. I turned off UAC, but it still does not work.

I want the folder to end up it the root directory where the index.php is (outside of application folder).

function create_user($data, $activated = TRUE)
    {
        $data['created'] = date('Y-m-d H:i:s');
        $data['activated'] = $activated ? 1 : 0;

        if ($this->db->insert($this->table_name, $data)) {
            $user_id = $this->db->insert_id();
            if(!is_dir("./uploads/".$user_id)){
                mkdir("./uploads/".$user_id , 0777);
            }

            if ($activated) $this->create_profile($user_id);
            return array('user_id' => $user_id);
        }
        return NULL;
    }

1条回答
Ridiculous、
2楼-- · 2019-08-29 11:06

Your problem is the directory is not relative to index.php - it needs to be absolute to index.php

Change

 if(!is_dir("./uploads/".$user_id)){
            mkdir("./uploads/".$user_id , 0777);

To

if(!is_dir(FCPATH.$user_id)){
            mkdir(FCPATH.$user_id , 0777);
查看更多
登录 后发表回答