php - set_include_path(get_include_path().PATH_SEPARATOR. 'phpseclib');

标签 php ftp sftp phpseclib

我偶然发现了两个我以前从未在 php 中使用过的函数

set_include_path();
get_include_path();

我目前正在寻求将 phpseclib 实现到我正在开发的项目中。因为我需要使用 SSH2 的 SFTP 类扩展,而这又需要 MathBigInteger 类......等等。

手册中提到了set_include_path():

"Sets the include_path configuration option for the duration of the script. "

这对于我的框架的其余部分意味着什么?它会设置“phpseclib”目录中的所有包含路径吗?

另外,我真的不明白:

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');

我将 php sec 存储在我的文件系统中的自定义库目录中,get_include_path() 是否能够神奇地找到我的文件系统中的 phpseclib 目录?

正如你所看到的,我完全迷失在这里......有人可以为我提供一些启发吗?

PS/ 我只在应用程序的一个特定点需要这个库,因此只想在需要时包含它,目前我想将它包含在我的模型类的子级中。

最佳答案

首先你需要了解 include_path 是什么?配置设置的作用是:

Specifies a list of directories where the require, include, fopen(), file(), readfile() and file_get_contents() functions look for files. The format is like the system's PATH environment variable: a list of directories separated with a colon in Unix or semicolon in Windows.

PHP considers each entry in the include path separately when looking for files to include. It will check the first path, and if it doesn't find it, check the next path, until it either locates the included file or returns with a warning or an error. You may modify or set your include path at runtime using set_include_path().

结构

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');

phpseclib 附加到当您请求包含具有上述功能之一的文件时搜索的目录列表。

由于 phpseclib 是相对路径,因此效果与指定 ./phpseclib 相同,即 PHP 将查找名为 phpseclib 的子目录 在进程的当前目录内。它不会神奇地确定库在文件系统中的位置;您的工作是将其放在可以找到的地方。

关于php - set_include_path(get_include_path().PATH_SEPARATOR. 'phpseclib');,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14295164/

相关文章:

linux - 通过 cronjob 中的 bash 脚本进行 sftp : 'get' and 'rm' commands not found?

php - fatal error :未捕获异常 'Exception',消息为“DateTime::__construct(): 无法解析时间字符串

java - 如何使用 Java 中的 FTP 在大型机上创建数据集

linux - 如何检测ftp连接

linux - 通过 shell,添加具有斜杠路径 ("/") 的用户作为目录 : ssh/sftp impossible,,即使在使用命名目录重新创建它之后也是如此

c# - 无法使用 rebex sftp 保存动态创建的 MemoryStream

php - foreach 与 array_chunk 在 php 和多个数组

java - 从 PHP 脚本调用 Swing Java 应用程序

php - 为什么我不能——或者我如何——使用 WordPress API 将 NULL 值插入我的 MySQL 数据库

java - Spring FTP 入站 channel 适配器 - 只需每 5 分钟登录一次