Php 如何读取codeigniter文件夹外的文件

Php 如何读取codeigniter文件夹外的文件,php,codeigniter,path,readfile,Php,Codeigniter,Path,Readfile,我有一个项目要从codeigniter目录之外但在同一服务器中读取文件 例如: codeigniter文件夹路径: opt/xampp/htdocs/yourprogramname/application 但我想从以下位置读取文件: 购买/dashboard/filename.txt 我的用户代码: $handle = fopen("purchase/dashboard/filename.txt", "r"); echo $handle; ?> 我如何在代码点火器中做到这一

我有一个项目要从codeigniter目录之外但在同一服务器中读取文件

例如:

codeigniter文件夹路径:

opt/xampp/htdocs/yourprogramname/application

但我想从以下位置读取文件:

购买/dashboard/filename.txt

我的用户代码:
  $handle = fopen("purchase/dashboard/filename.txt", "r");
  echo $handle;

  ?>

我如何在代码点火器中做到这一点?我知道如何从codeigniter(应用程序中的文件夹资源/etc)中的同一目录读取文件,但当我尝试时。//或../codeigniter不会读取文件内容

使用绝对路径。试试这个

<?php 

 $handle = fopen("/purchase/dashboard/filename.txt", "r");
 echo $handle;

?>

您可以使用
FCPATH

文件


嗯,我试着用你的例子,但我还是没有得到这样的文件或目录
application
purchase
purchase > dashboard
system
index.php
<?php 

if (file_exists(FCPATH . 'purchase/dashboard/filename.txt') {

   $handle = fopen(FCPATH . 'purchase/dashboard/filename.txt', "r");

   echo $handle;

}

?>
<?php 

if (file_exists('/purchase/dashboard/filename.txt') {

   $handle = fopen('/purchase/dashboard/filename.txt', "r");

   echo $handle;

}

?>
EXT: The PHP file extension
FCPATH: Path to the front controller (this file) (root of CI)
SELF: The name of THIS file (index.php)
BASEPATH: Path to the system folder
APPPATH: The path to the "application" folder