Error while deleting file with unlink

Asked

Viewed 359 times

1

How to remove a file with unlink?

the file is in this folder

/home/user/public_html/public/data/file.png

i am running unlink from that file

/home/user/public_html/admin/application/controllers/delete.php

I’m using codeigniter, meaning, /admin/ has a codeigniter and the public_html there’s another

Every time I try to remove him from that mistake

Erro

  • 4

    Just read the error message: "There is no such file or directory". You may even be seeing it in the directory but to the "eyes" of the Application, in case the file running unlink() could not be located. Edit your question with more information to try to help you with debug.

  • 1

    Welcome to stackoverflow, a tip, don’t use images to put error messages in the question, and put the code that error occurs here too. Read: http://answall.com/help/mcve :)

1 answer

1


Check before if the file exists using the command file_exists

The code would look something like this:

if(file_exists($caminho_para_arquivo)){
    unlink($caminho_para_arquivo);
}

More information here: http://php.net/manual/en/function.file-exists.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.