PHP Unlimited level Create directory several functions

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags create date directory function functions is_dir php programming

PHP Unlimited level Create directory several functions

function Mkdirs ($dir)
{
if (!is_dir ($dir)) {
if (!mkdirs (DirName ($dir)) {
return false;
if (!mkdir ($dir, 0777)) {
return false;
}
return true;
}
Test method
$img _path = Realpath ("../../../upfile/www.jzread.com/"). ' /'. Date ("y/m/d/");
Mkdirs ($img _path);

function.
function Mkdir_r ($dirname, $rights =0777) {
$dirs = explode ('/', $dirname);
$dir = ';
foreach ($dirs as $part) {
$dir. = $part. /';
if (!is_dir ($dir) && strlen ($dir) >0)
mkdir ($dir, $rights);
}
}

$path = "www.jzread.com/". Date ("y/m");
Mkdir_r ($path);
/*
Creating a directory is something that is often encountered in a file upload, and if I want to generate a relative directory based on the date and save the file, this will be required.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.