admin 发表于 2025-5-26 19:22:44

php检查目录是否存在,不存在则创建

代码:

$directoryPath = "/path/to/your/directory";

if (!is_dir($directoryPath)) {
    // 尝试创建目录
    if (mkdir($directoryPath, 0777, true)) {
      echo "目录创建成功。";
    } else {
      echo "目录创建失败。";
    }
} else {
    echo "目录已存在。";
}

页: [1]
查看完整版本: php检查目录是否存在,不存在则创建