Search code examples
phpcodeigniter

unlink a php file in Codeigniter project?


i am trying to delete a php file with unlink function in Codeigniter? it has a path:

./public_html/application/views/driver/tobedeleted.php

so to delete this file i created a route like

$route['delete']='my_controller/delete';

and in my controller's delete function i am executing a testdelete.php script which is inside my web directory.

public function delete(){
      $this->load->view('web/testdelete');
  }

and here is the code of testdelete.php:

<?php 

  unlink("./public_html/application/views/driver/tobedeleted.php");

  ?>

but whenever i try to do that it says:

file not found

can anyone help me with this . Thanks in advance <3.


Solution

  • please use:

    unlink(FCPATH."/application/views/driver/tobedeleted.php");
    

    FCPATH carries root path till the application folder.