[thelist] PHP deleting a file
Kasimir K
evolt at kasimir-k.fi
Wed Oct 12 06:37:54 CDT 2005
Jeremy Weiss scribeva in 2005-10-12 10:48:
> I'm needing some help with the following PHP script. I'm trying to check and
> see if $oldphoto is equal to nophoto.gif. It if is equal I want it to do
> nothing. Otherwise I want it to delete $oldphoto. The problem is, it deletes
> $oldphoto either way.
>
> if ($oldphoto != "nophoto.gif") {
> // Delete the agents existing photo
> @unlink("$oldphoto");
> }
If @unlink("$oldphoto"); is executed, then $oldphoto very much is not
"nophoto.gif". So instead of trying to find error in this if block, I'd
concentrate on what value $oldphoto actually has. Maybe you assign it
somewhere with an extra space, like $oldphoto = " nophoto.gif".
So when you say, that it deletes $oldphoto either way, do you mean it
deletes file nophoto.gif? But if nophoto.gif does not exist, and you've
got the @ there, then you don't really need the whole if statement...
you just delete the $oldphoto anyway, and if it happens to be
"nophoto.gif", then nothing is deleted.
hth
.k
More information about the thelist
mailing list