From the PHP docs on the empty
function:
Note:
Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.
So you will have to split that line into something like the following:
$trimDir = trim($Directory);
if(!empty($trimDir))