PHP is_file和服务器根相对路径 [英] PHP is_file and server root relative paths

查看:274
本文介绍了PHP is_file和服务器根相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



谢谢!

解决方案

如果路径以/开头,则表示路径是绝对路径。当路径是相对的(即不是以/开始),则相对于PHP脚本的路径被采取。如果你想拥有/folder/file.jpg相对于服务器的根,你可以附加根。

  $ path = $ _SERVER ['DOCUMENT_ROOT']。 /folder/file.jpg; 


How can I use is_file with a path like: /folder/file.jpg please?

Thank you!

解决方案

If the path starts with a / this means the path is absolute. When the path is relative (ie not starting with /) then the path relative to the php script is taken. If you want to have /folder/file.jpg relative to the server root, you can append the root.

$path = $_SERVER['DOCUMENT_ROOT'] . '/folder/file.jpg';

这篇关于PHP is_file和服务器根相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆