In CodeIgniter, there are available defined filepath constants inside the /public/index.php.

There are following constants available:

  • BASEPATH returns C:/wamp/www/testci2_2.dev/system/
  • SELF returns index.php
  • SYSDIR returns system
  • FCPATH returns C:\wamp\www\testci2_2.dev\public\

Inside my controller /application/controllers/configurations.php within a function backup() method, I would like to make backup files write directly to the /sql/ folder which is located here: C:\wamp\www\testci2_2.dev\sql\

I tried to use var_dump(dirname(BASEPATH) . '/sql/'); which produces what I want, but I am not quite sure if it's the best way to do that, maybe there is smarter steps to get that path ?

How can I target that folder by using some of this constants ?
If it is not possible, is there any other CLEVER method so when one day I decide to move controllers into the subfolders or so, they will not loose the track from specified folders ?

有帮助吗?

解决方案

You need to use pathinfo to extract the directory name from FCPATH prior to \public\

$path = pathinfo(FCPATH, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR;
echo $path; // C:\wamp\www\testci2_2.dev\sql\
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top