如何确定 PHP_URL_PATH 的最后一部分是文件还是目录?
上下文:我正在尝试分层存储 URI(从 3758 TLD 开始,在域中进一步细化,在路径中进一步细化,在查询字符串中进一步细化){并按协议、端口等进行划分),基本上将网络存储为一棵大树,我试图存储它并将元数据(例如网站图标、Alexa 排名、SU 排名、美味的 MD5 和链接等)附加到正确的节点,而不是在节点上复制信息,因此父/子层次结构是需要的,因为意识到树的概念并不真实,但在实际意义上非常有用。
问题:如果我使用 parse_url 作为路径:
$url_path = parse_url($uri, PHP_URL_PATH);
在拆分并将这些位存储在数据库中之前确定最后一个元素是文件还是文件夹的最佳方法是什么?例如,如果我向该 URI 部分发出 http 请求,我能否可靠地找出该字符串最后一部分的真实性质?
示例:
/foo/bar/imnot.php
如何可靠地确定imnot.php是文件还是目录? (当然除了打电话给开发商)
Context: I'm trying to hierarchically store URI's (starting with 3758 TLD's, further refined in domains, further refined in paths, further refined in querystrings) {and divided in protocols, ports, etc), basically storing the web as one big tree and I'm trying to store it and attach meta data such as favicons, alexa rankings, SU rankings, delicious MD5 and links, etc... to the correct node by not duplicating information over nodes therefore a parent/child hierarchy is needed where realizing that the tree concept is not true but in a practical sense very useable.
Question: If I use parse_url for the path:
$url_path = parse_url($uri, PHP_URL_PATH);
What is the best way to determine if the last element is a file or a folder before splitting and storing the bits in the database? E.g. if I make a http request out to that URI part could I reliably find out the true nature of this last part of this string?
Example:
/foo/bar/imnot.php
How to reliably find out if imnot.php is a file or directory? (other than calling the developer ofcourse)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当谈论 URL 时,没有“文件”或“目录”的概念。
例如,/foo/bar 可以是一个有效的 URL,为您提供有关 bar 的信息,但 /foo/bar/node 也可以是一个有效的 URL,为您提供有关 bar 的节点信息。在这种情况下,bar 的作用既像文件又像目录。这很常见,只要看一下 SO 的 URL 即可。
There is no notion of "file" or "directories" when talking about URLs.
For example /foo/bar could be a valid URL that gives you information about bar but /foo/bar/node could also be a valid URL that gives you node information about bar. In this case, bar acts like both a file and a directory. This is pretty common, just take a peek at SO's URLs.