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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化