绝对文件路径
这个问题仍然没有解决
我正在关注的视频PHP教程正在构建一个名为initialize.php的文件,其中它使用PHP预定义的常量Directory_Separator,然后定义一个site_root。 site_root 是 PHP 查找所需文件的绝对文件路径(不是网络服务器路径)。他给了我们以下代码
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null :
define ('SITE_ROOT', DS.'Users'.DS.'kevin'.DS.'Sites'.DS.'photo_gallery');
我假设他计算机上的文件路径是 root/users/kevin/sites/photogallery
我不是在我的计算机上构建该网站,而是直接在线构建该网站。我不知道要插入哪个文件路径。
正如他强调的那样,这不是网络服务器路径,而是文件系统路径,我该放什么。就这样的域名。
define('SITE_ROOT', DS. 'www.example.com');
他不想要网络服务器路径,但文件位于网上?所以我不明白。
更新
视频教程使用了以下代码
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null :
define ('SITE_ROOT', DS.'Users'.DS.'kevin'.DS.'Sites'.DS.'photo_gallery');
defined('LIB_PATH') ? null : define('LIB_PATH',SITE_ROOT.DS.'includes');
我使用了此代码:
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT')? null: define('SITE_ROOT', realpath(dirname(__FILE__)));
defined('LIB_PATH') ? null : define('LIB_PATH',SITE_ROOT.DS.'includes');
我收到此错误消息
require_once(/hsphere/local/home/c263430/quoralist.com/includes/includes/config.php): 无法打开流:没有这样的文件或 目录在 /hsphere/local/home/c263430/quoralist.com/includes/initialize.php 第 11 行致命错误: require_once(): 打开失败 必需的 '/hsphere/local/home/c263430/quoralist.com/includes/includes/config.php' (include_path='.:/hsphere/shared/apache/libexec/php5ext/php/') 在 /hsphere/local/home/c263430/quoralist.com/includes/initialize.php 第 11 行
更新 使用experimentX进行以下3次编辑,以及以下
define('SITE_ROOT', DS.'hsphere'.DS.'local'.DS.'home'.DS.'c263430'.DS.'quoralist.com');
我总是收到错误消息
警告: require_once(LIB_PATH/config.php): 无法打开流:没有这样的文件或 目录在 /hsphere/local/home/c263430/quoralist.com/includes/initialize.php 第 11 行致命错误: require_once(): 打开失败 需要“LIB_PATH/config.php” (include_path='.:/hsphere/shared/apache/libexec/php5ext/php/') 在 /hsphere/local/home/c263430/quoralist.com/includes/initialize.php 第 11 行
此外,
This problem is still not solved
A video PHP tutorial I am following is building a file called initialize.php in which it is using the PHP pre-defined constant Directory_Separator and then defining a site_root. The site_root is the absolute file path (not the webserver path) for PHP to locate the files it needs. He gave us the following code
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null :
define ('SITE_ROOT', DS.'Users'.DS.'kevin'.DS.'Sites'.DS.'photo_gallery');
I am assuming the file path on his computer is root/users/kevin/sites/photogallery
I am not building the site on my computer, but rather directly online. I don't know what file path to insert instead.
As he emphasized that it's not the webserver path, but rather the file system path, what do I put instead. Just the domain name like this.
define('SITE_ROOT', DS. 'www.example.com');
He doesn't want the webserver path but the files are located online? so I don't get it.
UPDATE
The video tutorial used the following code
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null :
define ('SITE_ROOT', DS.'Users'.DS.'kevin'.DS.'Sites'.DS.'photo_gallery');
defined('LIB_PATH') ? null : define('LIB_PATH',SITE_ROOT.DS.'includes');
I used this code:
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT')? null: define('SITE_ROOT', realpath(dirname(__FILE__)));
defined('LIB_PATH') ? null : define('LIB_PATH',SITE_ROOT.DS.'includes');
I got this error message
require_once(/hsphere/local/home/c263430/quoralist.com/includes/includes/config.php):
failed to open stream: No such file or
directory in
/hsphere/local/home/c263430/quoralist.com/includes/initialize.php
on line 11 Fatal error:
require_once(): Failed opening
required
'/hsphere/local/home/c263430/quoralist.com/includes/includes/config.php'
(include_path='.:/hsphere/shared/apache/libexec/php5ext/php/')
in
/hsphere/local/home/c263430/quoralist.com/includes/initialize.php
on line 11
UPDATE
using the 3 edits below by experimentX, as well as the following
define('SITE_ROOT', DS.'hsphere'.DS.'local'.DS.'home'.DS.'c263430'.DS.'quoralist.com');
I always got the error message
Warning:
require_once(LIB_PATH/config.php):
failed to open stream: No such file or
directory in
/hsphere/local/home/c263430/quoralist.com/includes/initialize.php
on line 11 Fatal error:
require_once(): Failed opening
required 'LIB_PATH/config.php'
(include_path='.:/hsphere/shared/apache/libexec/php5ext/php/')
in
/hsphere/local/home/c263430/quoralist.com/includes/initialize.php
on line 11
Also,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不如
使用
define('SITE_ROOT', 'www.domain.com')
来代替define('SITE_ROOT', realpath(dirname(__FILE__))
。www.domain.com
是(您网站的)基本 url,而realpath(dirname(__FILE__))
是定义 FILE 的绝对文件路径。您可以为您的网站设置一个根文件夹,例如:您不能执行
unlink('www.example.com\img1.jpg')
来删除img1
您应该这样做。 do
unlink(SITE_ROOT.DS.'img1.jpg')
;对于
move_uploaded_file
或任何其他目录或文件功能,即您的文件正在被服务器计算机移动和删除。 需要绝对文件路径,您可以导航到服务器上的文件夹并访问文件
(因为 php 脚本是在服务器中执行的),因此
。 -root 在 Mac 上是
Users/kevin/Sites/
,而Users/kevin/Sites/photogallery
是网站根目录。导师知道这一点,所以他才这样做。但是当我们的项目上传到网络服务器时我们可能不知道这一点,所以
这是最合适的。
至于
DS
,它只是一个CONSTANT(DIRECTORY_SEPARATOR
),定义它是因为DIRECTORY_SEPARATOR
写起来太长。即,因此,在定义 SITE ROOT 之前先定义它,
因为本教程是在 MAC 上完成的,
DIRECTORY_SEPARATOR
是/
。示例是在localhost
上完成的,导师知道他的网络服务器的绝对文件路径,因此他正在执行[错误:更新]
您收到此错误是因为在 < code>includes/initialize.php 假设您的
SITE_ROOT
是yourwebroot/yourproject/includes
,它必须是yourwebroot/yourproject/includes< /代码>。
有两种方法,一种方法是
将
initialize.php
放在yourwebroot/yourproject
中,另一种方法是
OR
(我不确定,但其中一个应该有效)
另外试试这个
How about
Instead of
define('SITE_ROOT', 'www.domain.com')
you shoulddefine('SITE_ROOT', realpath(dirname(__FILE__))
.www.domain.com
is the base url (of your site) whilerealpath(dirname(__FILE__))
is the absolute file path of FILE where it is defined. Using this path, you can set up a ROOT FOLDER for you site.For example: you cannnot do
unlink('www.example.com\img1.jpg')
to deleteimg1
You should do
unlink(SITE_ROOT.DS.'img1.jpg')
;Similarly for
move_uploaded_file
or any other directory or file function. i.e. your files are being moved and deleted by server computer(as php script is executed in server), so absolute file path is required.Using this absolute path, you can navigate to the folder and access files on server.
[UPDATE]
Though I don't own mac, the
web-root
isUsers/kevin/Sites/
on Mac and theUsers/kevin/Sites/photogallery
is the site root.The tutor knows this so he is doing this. But we might not know this when our project is uploaded in webserver, so
Would be the most appropriate.
And as to
DS
, it is just a CONSTANT (DIRECTORY_SEPARATOR
), which is defined becauseDIRECTORY_SEPARATOR
would be too long to write. i.e.So, define it before you define SITE ROOT
As the tutorial is done on MAC
DIRECTORY_SEPARATOR
is/
. And the sample is done onlocalhost
, the tutor knows the absolute file path of his webserver so he is doing[ERROR: UPDATE]
You got this error because defining this on
includes/initialize.php
assumes that your yourSITE_ROOT
isyourwebroot/yourproject/includes
where it must have beenyourwebroot/yourproject/includes
.There are two ways, one way is
to put
initialize.php
inyourwebroot/yourproject
And the other way is
OR
(I am not sure but one of them should work)
Also try this
答案
抱歉,我对 IMAGES not displayed in Photograph.php,只需删除 DS
工作行的
是:谢谢!
sorry, i have the answer for IMAGES not displaying
in photograph.php, just remove DS
working line is:
Thanks!