如果文件夹不存在,请创建一个文件夹 [英] Create a folder if it doesn't already exist

查看:186
本文介绍了如果文件夹不存在,请创建一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到几例WordPress安装与Bluehost,我遇到错误与我的WordPress主题,因为上传文件夹 wp-content / uploads 不是现在。

I've run into a few cases with WordPress installs with Bluehost where I've encountered errors with my WordPress theme because the uploads folder wp-content/uploads was not present.

显然,Bluehost cPanel WP安装程序不会创建此文件夹,尽管HostGator可以。

Apparently the Bluehost cPanel WP installer does not create this folder, though HostGator does.

所以我需要添加代码到我的主题,检查文件夹,否则创建。

So I need to add code to my theme that checks for the folder and creates it otherwise.

推荐答案

尝试这个:

if (!file_exists('path/to/directory')) {
    mkdir('path/to/directory', 0777, true);
}

请注意, 0777 已经是目录的默认模式,可能仍然被当前的umask修改。

Note that 0777 is already the default mode for directories and may still be modified by the current umask.

这篇关于如果文件夹不存在,请创建一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆