Several functions for creating directories at unlimited levels in PHP

高洛峰
Release: 2016-11-29 15:53:11
Original
1107 people have browsed it

Creating a directory is something we often encounter when uploading files. If I want to generate a relative directory based on the date and save the file, I need this function. The example code is as follows:

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..php.cn/") .'/'.date("y/m/d/");

mkdirs($img_path);

//function

function mkdir_r($dirname, $rights=0777){

$dirs = explode('/', $dirname);

$dir='';

foreach ($dirs as $part) {

as $part.'/';

if (!is_dir($ dir) && strlen($dir)>0)

                                                                                                                                                                                 );

mkdir_r($path);

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!