php file directory separator linux compatibility issues with Windows

Then both systems, Windows separator is "\", linux is "/", so when matching files in the directory may experience system is not compatible wrong, it is generally defined as a directory separator use php constants:DIRECTORY_SEPARATOR

  In Windows, a slash ( / ) and backslash ( \ ) can be used as directory separator on linux path delimiter is /, which leads to a problem, such as the development machine is windows, there is a picture Upload program ,, and we use the (\) as a file delimiter, specified on the debug machine upload file directory is:

define('ROOT', dirname(__FILE__)."\upload"),
In all normal local debugging, but uploaded to the linux server will find the time to be wrong.
The problem is that in a document separator on the windows habitual use of \ as file separator, but on linux people know this is not identified, people only know /, so will the introduction of the following php built-in variable a : DIRECTORY_SEPARATOR.
The above wording can be rewritten as the following error-free writing:
define('ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR."upload");
This will ensure that no wrong.
For example discuz which is written like this:
define('S_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);
Back to the issue itself, DIRECTORY_SEPARATOR is associated with a return path operating system separator of php built-in command, return on windows \, and return to class on linux or unix /, is such a difference, usually containing the file path in the definition or upload directory will be used when saving.


Guess you like

Origin www.cnblogs.com/linqingvoe/p/10941719.html