doubao12345 2017-03-01 05:55
浏览 27
已采纳

如何在PHP中创建一个文件夹?

Now in my code one folder is createed like private/119 when I logged into my application. The code is,

if (!is_dir('private/'.$q->row()->userId)) {
    $oldmask = umask(0);
    $q=mkdir('private/' .$q->row()->userId,0777,true);
    umask($oldmask);
    copy('public/images/default_user.png','private/'.$q->row()->userId.'/default-profile_pic.png');
}

Now I want to create a one more folder inside that userId(119) folder. How to do that? I have tried something like that $q=mkdir('private/' .$q->row()->userId .'/beforeconvert',0777,true); but it is not working.

Or is the following code is correct?

if (!is_dir('private/'.$q->row()->userId) && !is_dir('private/'.$q->row()->userId .'/beforeconvert')) {
    $oldmask = umask(0);
    $q=mkdir('private/' .$q->row()->userId,0777,true);
    $create_folder = mkdir('private/' .$q->row()->userId .'/beforeconvert',0777,TRUE);
    umask($oldmask);
    copy('public/images/default_user.png','private/'.$q->row()->userId.'/default-profile_pic.png');
}
  • 写回答

1条回答 默认 最新

  • dongyuandou2521 2017-03-01 07:22
    关注

    According to your code direcoty beforeconvert will not created if parent directory : $q->row()->userId already exist.

    Also you don't need to create first parent directory then child. You can directly create child directory with mkdir it will create parent directory also.

    Change your code as below:

    <?php
    if (!is_dir('private/'.$q->row()->userId .'/beforeconvert')) {
        $oldmask = umask(0);    
        $create_folder = mkdir('private/' .$q->row()->userId .'/beforeconvert',0777,TRUE);
        umask($oldmask);
        copy('public/images/default_user.png','private/'.$q->row()->userId.'/default-profile_pic.png');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题