douaoli5328 2017-01-09 05:26
浏览 128

PHP使用正斜杠创建目录名称

I'm beginner in php. With a scenario i wanted to create directory with forward slash in name(09/01/2017). How can i resolve it?

$my_date = "09/01/2017"
$new_path = "../Images/".$my_date;

if(!file_exists($new_path)) {
    mkdir($new_path , 0777);
}

EDIT: I'm using macos with php server in it. In macos it is possible to create folder with slashes.

  • 写回答

2条回答 默认 最新

  • doumi1912 2017-01-09 05:49
    关注
    <?php 
    
    $my_date = "09/01/2017";
    $new_path = "images/".$my_date;
    if (!is_dir($new_path))
    {
        mkdir($new_path , 0777,true);
    }
    ?>
    

    mkdir($new_path , 0777,true);//true for recursive directory creation.

    In your case if you create directory with 09/01/2017 it will be created

    File Tree:
    
    images
    --09
     --01
      --2017
    

    because file system not allowed forward slash as directory name.Instead of this you can create 09012017 or 09-01-2017.

    评论

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch