search

Home  >  Q&A  >  body text

About PHP’s file_exists function

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梦2720 days ago756

reply all(5)I'll reply

  • 欧阳克

    欧阳克2017-06-23 09:13:41

    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

    reply
    0
  • PHP中文网

    PHP中文网2017-06-23 09:13:41

    Correct answer upstairs~

    reply
    0
  • ringa_lee

    ringa_lee2017-06-23 09:13:41

    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.

    reply
    0
  • 欧阳克

    欧阳克2017-06-23 09:13:41

    The correct answer upstairs is to at least get the site root directory and put it together.

    reply
    0
  • PHP中文网

    PHP中文网2017-06-23 09:13:41

    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.

    reply
    0
  • Cancelreply