I'm trying to upload some files and in order to that I also need the mimetypes. While for the first few files mime_content_type
seemed to work, I noticed that when the (absolute) path contains certain characters it fails.
I tried some different file- and directory names with the following results:
$path = "C:\Users\Desktop\empty.txt";
mime_content_type($path);
//Warning: mime_content_type(C:\Users\Desktop{empty-square}mpty.txt): failed to open stream: No such file or directory
$path = "C:\Users\Desktop\tempty.txt";
mime_content_type($path);
//Warning: mime_content_type(C:\Users\Desktop empty.txt): failed to open stream: No such file or directory
$path = "C:\Users\Desktop\xemptydir\xempty.txt";
mime_content_type($path);
//Warning: mime_content_type(C:\Users\Desktop{empty-square}mptydir{empty-square}mpty.txt): failed to open stream: No such file or directory
$path = "C:\Users\Desktop\lemptydir\lempty.txt";
mime_content_type($path);
//OK
So it became a little more clear after I saw \t
turning into a tab space, that characters like \e
, \t
, \n
, \x
are causing this problem. I thought maybe escaping will solve the issue, so I tried addslashes()
but that just gave me the same result. So how can I fix this problem?
edit
After posting the question I noticed the "empty squares" (similar to this □) disappeared so I put it in curly brackets so you know there's a empty square there.