doujing2497 2015-10-02 20:41
浏览 47
已采纳

PHP mkdir没有按预期工作

I'm working on some PHP that will create a folder every time a request is made to my server. I can't seem to get my syntax proper. If I just used the $date variable it works no problem, however when I add the "clean" folder before it, it won't create the folder.

<?php

$time = $_SERVER['REQUEST_TIME'];
$date =  date(Ymd_Hms, $time);
$new =  "clean/".$date;

echo $new;

if(!is_dir ($new))
{
    mkdir($new);
}

?>
  • 写回答

2条回答 默认 最新

  • dtjo87679 2015-10-02 20:47
    关注

    Put the in ' quotes and give the mkdir() appropriate params and it should work fine:

    <?php
    $time = $_SERVER['REQUEST_TIME'];
    $date =  date('Ymd_His', $time);
    $new =  "clean/".$date;
    
    echo $new;
    
    if(!is_dir ($new))
    {
    mkdir($new, 0777, true);
    }
    ?>
    

    mode: The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod()

    Note: mode is ignored on Windows.

    Return Values:

    Returns TRUE on success or FALSE on failure.

    Note: You don't have to create the folder clean first IF you're using the recursive = true option, Otherwise a folder named clean must be created first.

    PHP Manual: mkdir

    PS. I've created a directory using this code before posting so it should not have any problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题