[Phpwm] unlinking files
Phil Beynon
phil at infolinkelectronics.co.uk
Fri Sep 29 10:34:15 BST 2006
Found and eliminated an interesting bug in something I'm writing - didn't
spot it at first until I got an error against some earlier version database
data.
So this is just for general assistance of anyone doing the same sort of
thing.........
if the file it is trying to delete isn't in the database table the variable
thumb is empty, although it is defined.
It gets the subdirectory path therefore prepended to a nonexistant
filename - the result of which is it tries then to delete the entire
subdirectory - OOPS!
::::: The code was;
if(file_exists("./75px/" . $thumb_name)){unlink("./75px/" . $thumb_name);}
essentially this says if the file in this directory path exists then delete
it.
::::: It's now;
if(file_exists("./75px/" . $thumb_name) AND !is_dir("./75px/" .
$thumb_name)){unlink("./75px/" . $thumb_name);}
now it says if the files exists and its not just a directory path without a
file name then delete it
Note the inversion on is_dir()
It didnt actually manage to delete the directory, but it came up with the
sort of error message that has users disturbing techies! :-)
Regards,
Phil Beynon
Sales director
** Infolink Electronic Systems Ltd. http://www.infolinkelectronics.co.uk
** Professional Web Design & Cobalt Hosting Solutions
** Contact: Sales at infolinkelectronics.co.uk
** Tel / Fax 0121 441 3558 (home) 07801 548464 (mobile)
More information about the Phpwm
mailing list