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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号