agree with mr.potatoes.
looking at how you assigned $filename, i can't tell where it is. to me, your code says there is a directory named "path" that could be 1 step below your document root directory. that could be what you want it to say and where the file is, but is the script file within the document root? if it isn't, you will get an error. the best thing to do is this:
if your script file is in the root directory and the .ico file is in the 'path' directory that is 1 step under root, define $filename as:
$filename = './path/favicon.ico';
if your script is in the same 'path' directory with the .ico file, define $filename as:
$filename = 'favicon.ico';
if 'path' happens to be outside of your document root, define $filename as:
$filename = '../path/favicon.ico';
that should help you out.