【问题标题】:Create folder tree structure based on url PHP基于url PHP创建文件夹树结构
【发布时间】:2014-05-26 20:35:47
【问题描述】:

我正在从 git 中提取一些原始文件内容并在我的网站上显示这些内容。 这样我就不会在每次加载时都 ping github,我将这些文件内容缓存到一个简单的 txt 文件中。

一切都很好,花花公子。但我将它们全部缓存到同一个文件夹中。

我想做的是从这个 url 创建实际的文件夹树

https://raw.githubusercontent.com/octocat/Spoon-Knife/master/index.html

这样我的缓存文件就会保存为

octocat
--Spoon-Knife
---master
----test.txt

根据 url 创建此类文件夹结构的任何快速方法? 谢谢!

【问题讨论】:

标签: php github mkdir


【解决方案1】:

我认为这应该可行,它使用parse_url() 函数提取目录结构,并创建嵌套目录(如果它们不存在)。

$url = 'https://raw.githubusercontent.com/octocat/Spoon-Knife/master/index.html';

$path = parse_url( $url, PHP_URL_PATH );
$dir = __DIR__ . dirname($path) . '/';

if ( !file_exists( $dir ) ) {
    mkdir( $dir, 0777, true );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    • 2018-09-26
    相关资源
    最近更新 更多