Fix header
Use $tmpdname instead of dirname($tmpfname)