You must specify the file name in the content location:
header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
Edit: now this also means that if the file name contains a quote; then you need to avoid this quote. So now your code looks like this:
header('Content-Disposition: attachment; filename="' . str_replace('"', '\\"', ($mask ? $mask : basename($file))) . '"');
vcsjones
source share