Add error controls in readdir() and closedir() modules PHP code to fix issue #19