Dea*_*ang 5 php codeigniter path readfile
我有一个项目可以从外部codeigniter目录中读取文件,但在同一服务器中
例如:
codeigniter文件夹路径:
opt / xampp / htdocs /您的程序名称/应用程序
但我想从读取文件:
采购/仪表板/filename.txt
我的常用代码:
$handle = fopen("purchase/dashboard/filename.txt", "r");
echo $handle;
?>
Run Code Online (Sandbox Code Playgroud)
我该如何在代码点火器中执行此操作?我知道如何从codeiginiter(应用程序中的文件夹资源/等)的同一目录中读取文件,但是当我尝试././或../ codeigniter时,不会读取文件内容
小智 3
您可以使用
FCPATH
application
purchase
purchase > dashboard
system
index.php
Run Code Online (Sandbox Code Playgroud)
文件
<?php
if (file_exists(FCPATH . 'purchase/dashboard/filename.txt') {
$handle = fopen(FCPATH . 'purchase/dashboard/filename.txt', "r");
echo $handle;
}
?>
Run Code Online (Sandbox Code Playgroud)
或者
<?php
if (file_exists('/purchase/dashboard/filename.txt') {
$handle = fopen('/purchase/dashboard/filename.txt', "r");
echo $handle;
}
?>
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)