About PHP's file_exists function
过去多啦不再A梦
过去多啦不再A梦 2017-06-23 09:11:41
0
5
718

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?

过去多啦不再A梦
过去多啦不再A梦

reply all(5)
学霸

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

Ty80

Correct answer upstairs~

ringa_lee

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.

Ty80

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!