Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting file in codeigniter 3.1.4

I am using codeigniter 3.1.4.I am trying to delete a file in a folder in root directory.When i use unlink function as

$path=base_url()."files/image.jpg";
   unlink($path);

I got following Error:

A PHP Error was encountered

Severity: Warning

Message: unlink(): http does not allow unlinking

Filename: controllers/Deletion.php

Line Number: 12

Backtrace:

File: C:\xampp\htdocs\deletiontesting\application\controllers\Deletion.php
Line: 12
Function: unlink

File: C:\xampp\htdocs\deletiontesting\index.php
Line: 315
Function: require_once

When I use file helper for this purpose as

$this->load->helper('file');
        $path=base_url()."files/image.jpg";
        delete_files($path);

The file is not deleted.file name is image.jpg folder name is files .Please help me to delete that file

like image 451
Bibin Paul Avatar asked May 25 '17 07:05

Bibin Paul


People also ask

How do I delete a file in codeigniter 3?

you can use the "file helper" in codeigniter. 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.

How do I unlink an image in CI?

unlink(base_url(). '/image/logo_thumb'. $logo_thumb);


2 Answers

Use FCPATH

$path = FCPATH  . "/files/image.jpg";

unlink($path);
like image 151
Mr. ED Avatar answered Oct 02 '22 17:10

Mr. ED


Hello don't use the base_url when you are giving path to unlink wihtout base_url give path

$path="../files/image.jpg";
unlink($path);

This always works for me, it must be work for your code to.

if unlink($path); gives error then try @unlink($path);

i hope this will work for you

like image 23
Astound Avatar answered Oct 02 '22 16:10

Astound