即使文件在那里,附加带有 dirname(__FILE__) 的样式表也不起作用

发布于 2024-08-11 05:09:16 字数 589 浏览 2 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(4

木森分化 2024-08-18 05:09:16

相对路径应该没问题。

<LINK REL=StyleSheet HREF="../stylesheets/stylesheet.css" TYPE="text/css">

这里的绝对路径是相对于文档根的绝对路径,而不是文件系统的绝对路径。

dirname(__FILE__) 适用于包含服务器端的脚本文件,但不适用于客户端使用的路径。简而言之,链接标记是指示浏览器继续请求该文件的指令。

The relative path should be ok.

<LINK REL=StyleSheet HREF="../stylesheets/stylesheet.css" TYPE="text/css">

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.

萌面超妹 2024-08-18 05:09:16

从文件结构来看,/stylesheets/ 不在公众范围内,它必须放置在 /public/ 文件夹中,以便浏览器检索文件:

/data/main.php
/public/stylesheets/stylesheet.css
/public/index.php

即使文件 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:

/data/main.php
/public/stylesheets/stylesheet.css
/public/index.php

Even when the file main.php is working, the file being viewed by the browser is index.php, so the relative path would be stylesheets/stylesheet.css

动听の歌 2024-08-18 05:09:16

编辑:错误地阅读问题...

用于

<link rel="stylesheet" href="/stylesheets/stylesheet.css" type="text/css"/>

css

edit: read the question incorrectly...

use

<link rel="stylesheet" href="/stylesheets/stylesheet.css" type="text/css"/>

for css

萌酱 2024-08-18 05:09:16

这是部分区分大小写的问题吗Mac 操作系统?

Is this a problem with partial case-sensitivity on Mac OSX?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文