I would like to delete a file that is found in my localhost.
localhost/project/folder/file_to_delete
I\'m using codeigniter for this.
Try this, this works for me:
unlink("./path/to/folder/file_name_do_delete");
for example: I put my file inside uploads folder which is outside the application folder and my file name is 123.jpg. So it should be like this:
unlink("./uploads/123.jpg");
$file = "test.txt";
if (!unlink($file))
{
echo ("Error deleting $file");
}
else
{
echo ("Deleted $file");
}
you can use the "file helper" in codeigniter.
CodeIgniter v3: http://codeigniter.com/userguide3/helpers/file_helper.html#delete_files
CodeIgniter v4: http://codeigniter.com/user_guide/helpers/filesystem_helper.html#delete_files
and like this :
$this->load->helper("file");
delete_files($path);
Late Edit: delete_files
method uses a path to wipe out all of its contents via unlink()
and same you can do within CI. Like this:
unlink($path);
a valid path.