Today I used this function to determine whether the image exists, and encountered a problem.
if(file_exists("/ueditor/php/upload/image/20170621/1498038174913865.jpg")){
echo 1;
}else{
echo 0;
}
//输出0
<img src ="/ueditor/php/upload/image/20170621/1498038174913865.jpg" />
However, using the img tag on the same page can display the image correctly. why is that?
The address starting with / determined by file_exists is the absolute path of the Linux file, and the address starting with / in the img tag is the path relative to your url. The two paths are definitely different!
The basics of HTML and Linux are not enough
Correct answer upstairs~
Combined with the above, if you want to solve your problem.
The parameters in file_exists should be absolute addresses, you can try to use the __DIR__ constant.
If it is a framework, there will generally be corresponding constants used, so the definition and judgment will be relatively controllable.
The correct answer upstairs is to at least get the site root directory and put it together.
The basics are not good enough. One is the file system path and the other is the URL path. The two have nothing to do with each other. There is no relationship at all.
It looks similar, it’s just a coincidence.