PHP is_file 和服务器根相对路径

发布于 2024-09-29 00:34:55 字数 60 浏览 1 评论 0原文

请问如何使用 is_file 和 /folder/file.jpg 这样的路径?

谢谢你!

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

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久隐师 2024-10-06 00:34:55

如果路径以 / 开头,则表示该路径是绝对路径。当路径是相对路径时(即不以 / 开头),则采用相对于 php 脚本的路径。如果您希望 /folder/file.jpg 相对于服务器根目录,则可以附加根目录。

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

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';
人事已非 2024-10-06 00:34:55

使用 $_SERVER['DOCUMENT_ROOT'] :

$is_file = is_file($_SERVER['DOCUMENT_ROOT'] . '/folder/file.jpg');

Use $_SERVER['DOCUMENT_ROOT']:

$is_file = is_file($_SERVER['DOCUMENT_ROOT'] . '/folder/file.jpg');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文