Because you have rmdir( $target );
and rmdir( $target_thumb );
in your script. Get rid of it and you will have your directories left as you want.
PHP Manual: rmdir
— removes directory
Attempts to remove the directory named by dirname. The directory must be empty, and the relevant permissions must permit this. A E_WARNING level error will be generated on failure.
EDIT 1:
According you your last comment, you should debug your $target
and $target_thumb
variables:
echo '<pre>';
print_r( $target );
echo '</pre>';
What is the output for that? Make an edit to you question and provide the output and I will be able to help you out.
EDIT 2:
After looking at your posted code, I would strongly suggest to restructure it, as it's vulnurable to SQL injections: SQL injections in ADOdb and general website security