简体   繁体   English

PHP require_once奇怪地无法正常工作?

[英]PHP require_once oddly not working?

I'm trying to include a file in a page. 我正在尝试在页面中包含文件。 The file is located in a folder called phpThumb which is placed inside my wordpress theme directory. 该文件位于一个名为phpThumb的文件夹中,该文件夹位于我的wordpress主题目录中。
This is how I tried to include the file" 这就是我尝试包含文件的方式”

<?php require_once(get_bloginfo('template_url')."/phpThumb/phpThumb.config.php"); ?>

For some reason, this doesn't work. 由于某种原因,这不起作用。
I did check and get_bloginfo() returns a value and does not echo a value. 我做了检查,并且get_bloginfo() 返回一个值,并且没有回显一个值。
I triple checked the code for validity and it's all fine IMO... 我三遍检查了代码的有效性,这一切都很好,IMO ...

What could possibly be wrong? 有什么可能是错的吗?

PS ; PS; It worked using $_SERVER['DOCUMENT_ROOT'] but the output of it is dependent on the current page (correct me if I'm wrong) so it's not as efficient for me. 它使用$_SERVER['DOCUMENT_ROOT']起作用,但是它的输出取决于当前页面(如果我输入错了,请纠正我),因此对我而言效率不高。

require_once expects a file in a directory not a url. require_once期望目录中的文件不是URL。

Replace get_bloginfo('template_url') with the Wordpress function get_template_directory() . get_bloginfo('template_url')替换为Wordpress函数get_template_directory()

<?php require_once(get_template_directory()."/phpThumb/phpThumb.config.php"); ?> 

You're trying to require, not include. 您试图要求但不包括。 If you want to include do this: <?php include("page"); ?> 如果要包含,请执行以下操作: <?php include("page"); ?> <?php include("page"); ?>

$_SERVER['DOCUMENT_ROOT'] is not dependent on the current page/file. $_SERVER['DOCUMENT_ROOT']不依赖于当前页面/文件。 It will give you the system file path to your web root folder. 它将为您提供Web根文件夹的系统文件路径。 require_once expects a system file path. require_once需要系统文件路径。 So if your phpThumb.config.php is sitting at /dir1/dir2/phpThumb/phpThumb.config.php from your web root. 因此,如果您的phpThumb.config.php位于Web根目录的/dir1/dir2/phpThumb/phpThumb.config.php You would do this 你会这样做

require_once($_SERVER["DOCUMENT_ROOT"] . '/dir1/dir2/phpThumb/phpThumb.config.php');

Check the output of get_bloginfo('template_url')."/phpThumb/phpThumb.config.php" and compare it to the above. 检查get_bloginfo('template_url')."/phpThumb/phpThumb.config.php" ,并将其与上述内容进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM