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 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'