简体   繁体   中英

how to access a file in the application folder from a model?

How can I delete a file that resides in a child folder of Codeigniter's /application/ folder (eg /application/schematics/myfile.png ) from within a model?
I also have the path to the file like schematics/myfile.png .

您应该尝试这样做, APPPATH给出了到application文件夹的路径:

$path = APPPATH.'/schematics/myfile.png';

I recommend to create resources folders out of application folder. Because if you use htaccess, all that you put in url is redirected how param to index.php that it will redirect to right controller.

I use it this way:

  • application
  • system
  • css
  • js
  • img

In the index.php file in the root, most useful paths are defined so that you can use them within the rest of the code.

FCPATH   -> '/'
BASEPATH -> '/system/'
APPPATH  -> '/application/'

Or maybe try

$path = $_SERVER['DOCUMENT_ROOT'].'/application/schematics/myfile.png';
unlink(APPPATH.'schematics/myfile.png');

不管使用什么PHP框架, unlink()文件就像调用unlink()一样简单,但是由于使用的是CodeIgniter,因此可以使用APPPATH常量。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM