Iam trying toopen a jason file and decode it but o get this error on file_get_content:
file_get_contents(\country.json) [<a href=‘function.file-get-contents’>function.file-get-contents</a>]: failed to open stream: No such file or directory
countries are displayed and when i choose one it is saved on database.The only problem is when i load the page the index country are always the same (the first one) and not the country saved.
Except that / and \ have different meanings on different operating systems. However, as far as PHP functions are concerned, they are usually clever enough to replace / with \ (and vice-versa) as needed. One notable exclusion is realpath()
I meant to use / everywhere which should be safe in almost every modern OS(atleast in filesystem functions). \ is critical on everything non-windows and even in some windows-actions.
About realpath:
I’ not sure, but afaik win32-api returns path with backslashes and could be outdated a bit in some parts(but I have no clue how php accesses the hosts-filesystem)
Ah, it’s all very grown … Windows knows C:\ as well as \\ but sees / as the start of a parameter. Then again, spaces in path- and filenames are treated in a hackish way. Both, WinDOS and Unix, know \ as a shell escape for e.g. spaces and other stuff.
realpath() in very special in any regard as it not only tries to cut out relative locations (such as ../../) but also tries to verify that the resulting file location actually exists. As such, realpath() will return false if you feed it something like /usr\local/share.
But as far as file_get_contents goes, PHP is smart enough to translate path seperators into the according platform specific character. Ofc, on a framework-level one should spare PHP from any guessing by applying DIRECTORY_SEPARATOR. But I think it’s fine if you don’t do so in your app