Well, what is the error? I'm guessing its a Parse Error or T_ENCAPSED_STRING.
I can only see one thing:
$file_name = str_replace("\","",$file_name);
Your best bet right there, is to use:
$file_name = stripslashes($file_name);
Right now, you're escaping from PHP so that your string never really closes:
$file_name = str_replace(
" // Opens String
\" // Still in a string
, " // Closes string
" // Opens string
,$file_name); // String never ends.....
So you see, you're converting the rest of your code to a string (not what you want). Just remove that line, and replace it with what I suggested and it should work.
This is where using a syntax highlighting editor is nice. You can see right away that something is awry, and find it. I would suggest EditPlus if you don't have one. It's lightweight, and you can update the syntax files for PHP 5, or 4 whichever you use. Also works with HTML, Java, JavaScript, C, C#, PERL, you get the picture.
~Brett