Delete a specific Image from a File


I am currently working on a new project, using Codeigniter, it is my first experience and I do not find great help, I want the user to delete a photo chosen by him from his folder, The controller: '

public function delete()

A view: '

                                    <div class="col-sm-2">
                                    <img src="{path}" style="width: 100%; height: 100px;">
                                    <button name="nameimagetodelete" onclick="do_delete('{name}')"></button>


and JavaScript '

script type="text/javascript">
    function do_delete(name){
        var r = confirm("You sure?");
        if (r == true) 
            window.location.href = "<?php echo site_url('admin/delete');?>?name="+name;
            x = "Action canceled";


Thank you in advance!

asked by anonymous 08.06.2018 / 12:58

1 answer


Since you do not indicate which error you are getting, it makes it more difficult to help.

but may be due to lack of loading the condingniter lib responsible for the files

You can add the following line of code to your controller $ this- > load- > helper ('file');

then you may be having problems because you are using the absolute path of the file

08.06.2018 / 16:03