建立url或者路径path的文件夹
php中文网
/*** 建立url或者路径path的文件夹,并将url里的文件夹设置为可写, 如果不指定路径则在当前目录建立文件夹,否则在设置路径里建立文件夹。 $url : 可为任意目录形式url,如'1/2/3/4/'、'1/2/3/4'、'http://www.5jiuai.com/1/2/3/43/4/' $path : 可为任意形式的path,如'd:/test'、'd:\test' 返回 : 路径目录 例子: $url = 'http://www.5jiuai.com/1/2/3/43/4/'; $path = 'd:/test'; echo create_folder($url,'d:/test'); */ function create_folder($url,$path=''){ $path_str = !empty($path) ? $path : realpath(dirname(__FILE__)); //当 $c_path==''时,取当前目录 $folder_path_str = preg_match('/\\\/i',$path_str) ? preg_replace('/\\\/i','/',$path_str) : $path_str; //将路径里的'\'全部转为'/' $folder_path_arr = preg_match('/\//i',$folder_path_str) ? explode('/',$folder_path_str) : array(); //将路径分割为数组 $no_http_url = preg_match('/http:\/\//i',$url) ? preg_replace('/http:\/\//i','',$url) : $url; //去除url中的'http://' 字符 $no_http_url = preg_match('/\\\/i',$no_http_url) ? preg_replace('/\\\/i','/',$no_http_url) : $no_http_url; //将url里的'\'全部转为'/' $folder_url_arr = preg_match('/\//i',$no_http_url) ? explode('/',$no_http_url) : array(); //将url分割为数组 $path_arr = @array_merge($folder_path_arr,$folder_url_arr); //合并数组 $path_way = ''; foreach($path_arr as $key => $val){ if(empty($val)) continue; //如果$val为空值,则跳转到下一步 $path_way .= $val.'/'; if(is_dir($path_way)) continue; //如果目录已经存在,则跳转到下一步 @mkdir($path_way); if(in_array($val,$folder_url_arr)) @chmod($path_way,0777); //将url里的目录设置为可写 } return $path_way; }
Copy after login
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
2 weeks ago
By DDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
CakePHP Tutorial
1378
52

