Well your problem is here:
if (!in_array($dirArray[$i],$fileName_database['filename'])){
The first parameter of the in_array()
function should be the value to seach for, the second, the array:
if (!in_array($fileName_database['filename'],$dirArray)){
EDIT:
To fix the other problem on line 48:
if (!in_array($fileName_database['filename'],$dirArray)){
Wait, this might not work. Let me think about it for a second!