1

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.

YTZ
  • 876
  • 11
  • 26
  • 1
    Have you tried using single quotes with escaped chars instead of double/magic qoutes? – admcfajn Jan 15 '19 at 21:48
  • @admcfajn ah god damnit, that solved it. Didn't even think of trying that out. Care to explain why it fails with the double quotes then? – YTZ Jan 15 '19 at 21:54
  • 2
    I could, but I think that this would do a better job than I can: https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – admcfajn Jan 15 '19 at 21:57

0 Answers0