我有一个项目来从外部codeigniter目录中读取文件但在同一服务器中
示例:
codeigniter文件夹路径:
选择/ XAMPP / htdocs中/ yourprogramname /应用
但我想阅读以下文件:
购买/仪表板/ FILENAME.TXT
我的代码:
$handle = fopen("purchase/dashboard/filename.txt", "r");
echo $handle;
?>
我怎么能在代码点火器中这样做?我知道如何从codeiginiter(应用程序中的文件夹资源/ etc)中的同一目录中读取文件但是当我尝试././或../ codeigniter不会读取文件内容
答案 0 :(得分:2)
您可以使用
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
答案 1 :(得分:1)
使用绝对路径。试试这个,
<?php
$handle = fopen("/purchase/dashboard/filename.txt", "r");
echo $handle;
?>