【发布时间】:2021-12-21 12:14:43
【问题描述】:
我正在尝试创建一个文件,但该方法一直给我这个警告
警告:mkdir():文件存在于
我的代码可以正常工作,但我现在厌倦了这个警告。
我的代码,目前是这样的。注意 $carFecha 它是一个 Date 目录。类似于“2021-10-01”。
$carFecha = "directory/to/a/date/"
if (!file_exists($carFecha)) { //If file doesnt exists
echo $carFecha."</br>"; //This echo isnt there, but im printing it, to see what $carFecha is trying to create.
mkdir($carFecha); //Create the file
}
最糟糕的部分,它有 4 个这样的代码,但只有当我到达这部分时才会失败。
【问题讨论】:
-
@0stone0 所以我也必须检查 is_dir()
-
这取决于您的用例。请阅读链接的问题。或者看看
is_dir -
尝试删除
$carFecha末尾的/ -
如果名称存在但它是一个常规文件,我认为当路径名以
/结尾时file_exists()不会为真