如何检查目录是否存在? “ is_dir”,“ file_exists”还是两者?

I want to create a directory if it does'nt exist already. 如果目录尚不存在,我想创建一个目录。 Is using is_dir enou
摘要由CSDN通过智能技术生成

本文翻译自:How do I check if a directory exists? “is_dir”, “file_exists” or both?

I want to create a directory if it does'nt exist already. 如果目录尚不存在,我想创建一个目录。

Is using is_dir enough for that purpose? 使用is_dir是否足以达到目的?

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

Or should I combine is_dir with file_exists ? 还是应该将is_dirfile_exists结合使用?

if ( !file_exists( $dir ) && !is_dir( $dir ) ) {
    mkdir( $dir );       
} 

#1楼

参考:https://stackoom.com/question/MlWN/如何检查目录是否存在-is-dir-file-exists-还是两者


#2楼

$year = date("Y");   
$month = date("m");   
$filename = "../".$year;   
$filename2 = "../".$year."/".$month;

if(file_exists($filename)){
    if(file_exists($filename2)==false){
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值