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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)