Creating directory in uploads: mkdir vs wp_mkdir_p

$file_dir = WP_CONTENT_DIR . 'uploadsfoo';Why wouldyou need to use wp_mkdir_p when mkdir can do its job h

$file_dir = WP_CONTENT_DIR . '/uploads/foo/';

Why would you need to use wp_mkdir_p when mkdir can do its job here?

if(!file_exists($file_dir))wp_mkdir_p($file_dir);

or

if(!file_exists($file_dir))mkdir($file_dir);
$file_dir = WP_CONTENT_DIR . '/uploads/foo/';

Why would you need to use wp_mkdir_p when mkdir can do its job here?

if(!file_exists($file_dir))wp_mkdir_p($file_dir);

or

if(!file_exists($file_dir))mkdir($file_dir);
Share Improve this question asked Apr 30, 2017 at 21:18 ToniqToniq 4476 silver badges15 bronze badges 1
  • You can look at wp_mkdir_p in source to see what it does. – Milo Commented Apr 30, 2017 at 22:12
Add a comment  | 

1 Answer 1

Reset to default 5

There is not much a difference but, for wp_mkdir_p() we can only pass the full path to attempt to create a folder. It is recursive directory creation function which check for the file_exists() or not. And moreover we don't need to pass the folder permission because it checks for the parent directory permission and sets the folder permission as that of the parent directory.

But, with mkdir() we need to check for the file_exists() function before creating a directory and the directory permission will be set as the permission defined by the WordPress itself during the setup.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745111245a4611865.html

相关推荐

  • Creating directory in uploads: mkdir vs wp_mkdir_p

    $file_dir = WP_CONTENT_DIR . 'uploadsfoo';Why wouldyou need to use wp_mkdir_p when mkdir can do its job h

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信