doris20141022 2013-11-18 12:51
浏览 52
已采纳

在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.

  • 写回答

1条回答 默认 最新

  • dtwk6019 2013-11-18 12:59
    关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况