i have a project to read file from outside codeigniter directory but in the same server
example :
codeigniter folder path:
opt/xampp/htdocs/yourprogramname/application
but i want to read file from :
purchase/dashboard/filename.txt
my ussual code :
$handle = fopen("purchase/dashboard/filename.txt", "r");
echo $handle;
?>
how could i do this in code igniter? i know how to read file from the same directory in codeiginiter (folder resource/etc in application) but when i tried ././ or ../ codeigniter wont read the file content
You can use
FCPATH
application
purchase
purchase > dashboard
system
index.php
File
<?php
if (file_exists(FCPATH . 'purchase/dashboard/filename.txt') {
$handle = fopen(FCPATH . 'purchase/dashboard/filename.txt', "r");
echo $handle;
}
?>
or
<?php
if (file_exists('/purchase/dashboard/filename.txt') {
$handle = fopen('/purchase/dashboard/filename.txt', "r");
echo $handle;
}
?>
Codeigniter path functions definitions
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
Use absolute path. Try this,
<?php
$handle = fopen("/purchase/dashboard/filename.txt", "r");
echo $handle;
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With