$idfile=fopen($nomefile,"w+");
Non dovrebbe essere

$idfile=fopen($dir."/".$nomefile,"w+");