How to read a file outside the codeigniter folder

I have a project for reading a file from the external codeigniter directory, but on the same server

example:

codeigniter folder path:

Manual / XAMPP / HTDOCS / yourprogramname / application

but I want to read the file:

purchase / panel / filename.txt

my custom code:     

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

  ?>

How can I do this in a code igniter? I know how to read a file from the same directory on the Internet code (the resource of the / etc folder in the application), but when I tried ././ or ../ codeigniter did not read the contents of the file

+4
source share
2 answers

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;

}

?>

Codeigniter path function 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
+2
source

. ,

<?php 

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

?>
0

Source: https://habr.com/ru/post/1684177/


All Articles