Warning function unlink is a directory

hi all

i am using this code line to delete image from folder


it works fine on my localhost.

But on my live hosting server i m getting this error

Warning: unlink(../graphics/) [function.unlink]: Is a directory in


Hi @vinpkl

There are two things. It looks as though $image is null, which is why the server is reporting that you are trying to unlink a directory.

Secondly, your live server should be set so as not to report errors as this can be a security flaw.

What versions of PHP do you have (a) on your localhost and (b) on your live server.

both localhost and live have php ver 5.3


if $image is null then i should write it as


or can you suggest any thing better ??


i tried again on localhost

i have two images for each product (2nd image is optional).

so some product have one image and some have two images.

so first image exists so it gets deleted always without error

BUT i am getting this error on second image which does not exists



Warning:  unlink(../graphics/) [function.unlink]: Permission denied

But if i am using “file_exists” function then this error should not occur ??

am i using “file_exists” in wrong way ??


straight from the manual:

file_exists — Checks whether a file or directory exists

but looking at the message it’s obvious that your variable is empty, which shouldn’t be the case, I assume.

yes if file doesnt exists, the variable will be empty.

so what should i do to remove that error ??


You need to check that it exists and that it is a file - ie it’s not a directory.

so you mean to say that

if variable will be empty then it will assume it as directory because in the path only directory exists

which i think is happening


Sure thing. In your statement


if $image2 is null, you’re left with


which is a directory

thanks for clarifying

i will modify it


1 Like

The “belt and braces” methods :slight_smile:

Try testing for is_file(), is_dir() or is_link()


thanks john


1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.