vinpkl
1
hi all
i am using this code line to delete image from folder
unlink("../graphics/".$image);
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
vineet
Gandalf
2
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.
vinpkl
3
both localhost and live have php ver 5.3
vineet
vinpkl
4
if $image is null then i should write it as
if(file_exists("../graphics/".$image))
{
}
or can you suggest any thing better ??
vineet
vinpkl
5
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
if(file_exists("../graphics/".$image2))
{
unlink("../graphics/".$image2);
}
error
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 ??
vineet
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.
vinpkl
7
yes if file doesnt exists, the variable will be empty.
so what should i do to remove that error ??
vineet
Gandalf
8
You need to check that it exists and that it is a file - ie it’s not a directory.
vinpkl
9
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
vineet
Gandalf
10
Sure thing. In your statement
unlink("../graphics/".$image2)
if $image2 is null, you’re left with
unlink("../graphics/")
which is a directory
The “belt and braces” methods 
Try testing for is_file(), is_dir() or is_link()
http://php.net/manual/en/function.is-file.php
system
Closed
14
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.