Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php include()中将本地计算机文件与整个文件夹链链接?(例如C:\folder\thumbnails.php而不是thumbnails.php)_Php_Include - Fatal编程技术网

如何在php include()中将本地计算机文件与整个文件夹链链接?(例如C:\folder\thumbnails.php而不是thumbnails.php)

如何在php include()中将本地计算机文件与整个文件夹链链接?(例如C:\folder\thumbnails.php而不是thumbnails.php),php,include,Php,Include,所以,让我试着解释一下: 我的网站系统,包括一个庞大的php文件列表,这些文件在一个复杂的链接系统中相互链接,形成一个单一的网站,现在已经失控了。我无法找到一种方法来放置特定类型的php文件(例如,下面主文件夹中的一个文件夹,其中包含特定类别的所有帖子),因为这样,附加文件夹中的php文件就无法链接到该文件夹之外的php文件 为了演示这个问题,我创建了一个路径为Acer(C:)/xampp/htdocs/displation/Photography/photos.php的文件,在路径Acer(C

所以,让我试着解释一下:

我的网站系统,包括一个庞大的php文件列表,这些文件在一个复杂的链接系统中相互链接,形成一个单一的网站,现在已经失控了。我无法找到一种方法来放置特定类型的php文件(例如,下面主文件夹中的一个文件夹,其中包含特定类别的所有帖子),因为这样,附加文件夹中的php文件就无法链接到该文件夹之外的php文件

为了演示这个问题,我创建了一个路径为Acer(C:)/xampp/htdocs/displation/Photography/photos.php的文件,在路径Acer(C:)/xampp/htdocs/displation/index.php中还有另一个php文件

我的index.php文件包含:

<?php 
include("Photography/photos.php") 
?>

<p>Hello, this is text from index.php</p>
<p>Hello, this is text from photos.php</p>

您好,这是index.php中的文本

My photos.php文件包含:

<?php 
include("Photography/photos.php") 
?>

<p>Hello, this is text from index.php</p>
<p>Hello, this is text from photos.php</p>
您好,这是photos.php中的文本

显然,index.php可以链接photos.php,因为它们共享相同的父文件夹(“演示”文件夹):(这就是index.php的样子)

但是,我找不到将index.php链接到photos.php的方法(另一种方法),因为index.php与photos.php不共享同一父文件夹(它不在“Photography”文件夹中,它在该文件夹之外)


那么,有没有一种方法可以使用index.php文件的整个路径链接php文件,并将其放在photos.php中,这样它就可以工作了?(Acer(C:)/xampp/htdocs/demon示弱/index.php)或者,有没有其他解决方案阻止我组织php文件并强制我将它们全部放在一个文件夹中?谢谢

首先检查您的目录

示例>

<?php
    echo getcwd();
?>
//Running this code will tell you the current directory
<?php
    include_once("...");
?>
<p>Hello, this is text from index.php</p>

//运行此代码将告诉您当前目录
并更改为包括(…)

示例>

<?php
    echo getcwd();
?>
//Running this code will tell you the current directory
<?php
    include_once("...");
?>
<p>Hello, this is text from index.php</p>

您好,这是index.php中的文本


首先检查您的目录

示例>

<?php
    echo getcwd();
?>
//Running this code will tell you the current directory
<?php
    include_once("...");
?>
<p>Hello, this is text from index.php</p>

//运行此代码将告诉您当前目录
并更改为包括(…)

示例>

<?php
    echo getcwd();
?>
//Running this code will tell you the current directory
<?php
    include_once("...");
?>
<p>Hello, this is text from index.php</p>

您好,这是index.php中的文本


导航到父文件夹

上面的文件夹

//using .. will navigate to the previous folder.
include("../index.php");

//repeat to keep traversing back
include("../../../index.php"); //would take you back three (3) folders

导航到父文件夹的步骤

上面的文件夹

//using .. will navigate to the previous folder.
include("../index.php");

//repeat to keep traversing back
include("../../../index.php"); //would take you back three (3) folders

如果你使用直接地址,你永远不会有问题

include_once(addslashes(realpath($_SERVER['DOCUMENT_ROOT'])).((DIRECTORY_SEPARATOR == '/') ? '/' : '\\\\')."Demonstration/Photography/photos.php");

关于硬盘中的补丁

////defining CONST for recognition your Operation System  is windows or linux or mac USE / OR \....
define('DS', ((DIRECTORY_SEPARATOR == '/') ? '/' : '\\\\'));
define('_Site_PATH_', addslashes(realpath(dirname(__FILE__))) . DS );

include_once(_Site_PATH_."Demonstration".DS."Photography".DS."photos.php");

如果你使用直接地址,你永远不会有问题

include_once(addslashes(realpath($_SERVER['DOCUMENT_ROOT'])).((DIRECTORY_SEPARATOR == '/') ? '/' : '\\\\')."Demonstration/Photography/photos.php");

关于硬盘中的补丁

////defining CONST for recognition your Operation System  is windows or linux or mac USE / OR \....
define('DS', ((DIRECTORY_SEPARATOR == '/') ? '/' : '\\\\'));
define('_Site_PATH_', addslashes(realpath(dirname(__FILE__))) . DS );

include_once(_Site_PATH_."Demonstration".DS."Photography".DS."photos.php");

我尝试了include(“../index.php”);它显示了一个错误“致命错误:在第2行的C:\xampp\htdocs\explication\Photography\photos.php中超过了30秒的最大执行时间”。第2行是photos.php的include函数。它应该返回一个文件夹到index.php,但它正在做其他事情……这听起来像是某种原因导致脚本花费太长时间。试着简单化一下,看看情况是否如此。
“Photography/test.php”
中包含
include(../include.php)的
php
文件;回显“\n成功”“/included.php”
上的一个文件,它只是回显类似于您的示例的内容
回显“这很有效”等一下,您还在“index.php”中包含“photos.php”吗?这将是一个无限循环,因此是错误的。是的,我是。现在我明白了为什么会有一个无限循环,从而产生一个错误。现在我删除了index.php中photos.php的链接,它现在就像一个符咒。谢谢@格雷斯索耶没有戏剧。正如@seongwonyoon所指出的,更改为
include_once()
可以防止php尝试重复循环;它显示了一个错误“致命错误:在第2行的C:\xampp\htdocs\explication\Photography\photos.php中超过了30秒的最大执行时间”。第2行是photos.php的include函数。它应该返回一个文件夹到index.php,但它正在做其他事情……这听起来像是某种原因导致脚本花费太长时间。试着简单化一下,看看情况是否如此。
“Photography/test.php”
中包含
include(../include.php)的
php
文件;回显“\n成功”“/included.php”
上的一个文件,它只是回显类似于您的示例的内容
回显“这很有效”等一下,您还在“index.php”中包含“photos.php”吗?这将是一个无限循环,因此是错误的。是的,我是。现在我明白了为什么会有一个无限循环,从而产生一个错误。现在我删除了index.php中photos.php的链接,它现在就像一个符咒。谢谢@格雷斯索耶没有戏剧。正如@Seongwonyoon所指出的,更改为
include_once()
可以防止php尝试重复循环。@GraceSawyer“致命错误:在第2行的C:\xampp\htdocs\explication\Photography\Photography.php中超过了30秒的最大执行时间”解决方法是将include更改为include_once这似乎也不起作用。我尝试这样做,并将目录结果复制到include()中,但它无法识别。然后,我试着包括(”file:///C:/xampp/htdocs/Demonstration/index.php但是,它也不起作用。这个file:///C.... 目录用于链接图像,但对php include也不起作用file:///... 目录和它的工作!非常感谢。如果你能在最终答案中加入一次include_,那就太好了。虽然不知道为什么它会起作用…但是谢谢你!!这很酷,另一种方法是转到父文件夹并使用您想要的文件夹。Ex)包括一次(../Photography/photos.php);我曾经尝试过include_(“../index.php”),结果成功了。然后我尝试了include(“../index.php”),这正是@Luke所说的,它也起了作用!!我以前也试过他的答案,但不起作用,现在同样的问题突然出现了……现在我不确定该使用哪种解决方案!不过,非常感谢