即使文件在那里,附加带有 dirname(__FILE__) 的样式表也不起作用
我有一个 PHP 类,它为我的 html 文件创建一个标头。它被包含,并且该文件再次被包含。所以我认为 dirname(__FILE__)
函数可以工作..但它说它找不到样式表..
我在 os x 上使用 mamp,当我将从 dirname(__FILE__)./../stylesheets/stylesheet.css
获取的路径放入终端,找到文件..我很确定路径是正确的。
这可能是什么原因?当我包含文件时,我总是使用 dirname(__FILE__)
,这有效。
谢谢
EDIT: Files and directories: /data/main.php /stylesheets/stylesheet.css /public/index.php In the main.php:
public function createHeader(){ `$stylesheetpath = dirname(__FILE__) . "/../stylesheets/stylesheet.css";` `$header = "\n";` return $header }
I have a PHP class that creates a header for my html file.. It's included, and that file is included again.. So I thought that the dirname(__FILE__)
function could work.. But it says it can't find the stylesheet..
I'm using mamp on os x, and when I take the path that I get from dirname(__FILE__)./../stylesheets/stylesheet.css
into the terminal, the file is found.. I'm pretty sure the path is correct.
What can be the reason for this? I use dirname(__FILE__)
all the time when I include files, that works..
Thanks
EDIT: Files and directories: /data/main.php /stylesheets/stylesheet.css /public/index.php In the main.php:
public function createHeader(){ `$stylesheetpath = dirname(__FILE__) . "/../stylesheets/stylesheet.css";` `$header = "\n";` return $header }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
相对路径应该没问题。
这里的绝对路径是相对于文档根的绝对路径,而不是文件系统的绝对路径。
dirname(__FILE__)
适用于包含服务器端的脚本文件,但不适用于客户端使用的路径。简而言之,链接标记是指示浏览器继续请求该文件的指令。The relative path should be ok.
An absolute path here would be absolute with respect to the document root, not the file system.
dirname(__FILE__)
is appropriate for including script files server-side, but not for paths used by the client. Simply put, the link tag is an instruction to the browser to go ahead and request that file.从文件结构来看,
/stylesheets/
不在公众范围内,它必须放置在/public/
文件夹中,以便浏览器检索文件:即使文件
main.php
正在工作,浏览器正在查看的文件是index.php
,因此相对路径将为stylesheets/stylesheet.css
>From you file structure,
/stylesheets/
is out of the public reach, it must be placed inside the/public/
folder for the browsers to retrieve the files:Even when the file
main.php
is working, the file being viewed by the browser isindex.php
, so the relative path would bestylesheets/stylesheet.css
编辑:错误地阅读问题...
用于
css
edit: read the question incorrectly...
use
for css
这是部分区分大小写的问题吗Mac 操作系统?
Is this a problem with partial case-sensitivity on Mac OSX?