如何读取codeigniter文件夹外的文件
how to read file outside codeigniter folder
我有一个项目可以从外部 codeigniter 目录读取文件,但在同一台服务器中
示例:
codeigniter 文件夹路径:
opt/xampp/htdocs/yourprogramname/application
但我想从 :
读取文件
purchase/dashboard/filename.txt
我常用的代码:
$handle = fopen("purchase/dashboard/filename.txt", "r");
echo $handle;
?>
我怎么能在代码点火器中做到这一点?我知道如何从 codeigniter 中的同一目录(应用程序中的文件夹 resource/etc)读取文件但是当我尝试 ././ 或 ../ codeigniter 不会读取文件内容
使用绝对路径。试试这个,
<?php
$handle = fopen("/purchase/dashboard/filename.txt", "r");
echo $handle;
?>
You can use 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;
}
?>
Codeigniter 路径函数定义
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
我有一个项目可以从外部 codeigniter 目录读取文件,但在同一台服务器中
示例:
codeigniter 文件夹路径:
opt/xampp/htdocs/yourprogramname/application
但我想从 :
读取文件purchase/dashboard/filename.txt
我常用的代码:
$handle = fopen("purchase/dashboard/filename.txt", "r");
echo $handle;
?>
我怎么能在代码点火器中做到这一点?我知道如何从 codeigniter 中的同一目录(应用程序中的文件夹 resource/etc)读取文件但是当我尝试 ././ 或 ../ codeigniter 不会读取文件内容
使用绝对路径。试试这个,
<?php
$handle = fopen("/purchase/dashboard/filename.txt", "r");
echo $handle;
?>
You can use
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;
}
?>
Codeigniter 路径函数定义
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