PHP's file_exists() will not work for me?

前端 未结 7 1724
既然无缘
既然无缘 2020-12-01 04:21

For some reason this PHP code below will not work, I can not figure it out.

It is very strange, file_exists does not seem to see that the image does exist, I have c

相关标签:
7条回答
  • 2020-12-01 04:47

    Have you enabled the option which allows you to use external URLs? You can set it in php.ini:

    allow_url_fopen = 1
    
    0 讨论(0)
  • 2020-12-01 04:49

    file_exists() needs to use a file path on the hard drive, not a URL. So you should have something more like:

    $thumb_name = $_SERVER['DOCUMENT_ROOT'] . 'images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
    if(file_exists($thumb_name)) {
        some_code
    }
    

    http://us2.php.net/file_exists

    0 讨论(0)
  • 2020-12-01 04:56

    Try Below one. Its working for me

    define('SITE_PATH2', 'http://localhost/');
    $noimg = SITE_PATH2. 'images/userphoto/noimagesmall.jpg';
    $thumb_name = 'http://localhost/images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
    
    if ($fileopen = @fopen($thumb_name)) {
        $img_name = $thumb_name;
        fclose($fileopen);
    }else{
        $img_name = $noimg;
    }
    echo $img_name;
    
    0 讨论(0)
  • 2020-12-01 04:57

    http://php.net/manual/en/function.file-exists.php

    did you check the comments below?

    Just reading parts of it, but there seem to be several issues.

    Caching may be a problem. When opening FTP urls it always returns true (they say in the comments) ...

    0 讨论(0)
  • 2020-12-01 05:00

    docs say:

    As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to List of Supported Protocols/Wrappers for a listing of which wrappers support stat() family of functionality.

    0 讨论(0)
  • 2020-12-01 05:00

    You have to write the file path like "file:///C:/Documents%20and%20Settings/xyz/Desktop/clip_image001.jpg".

    0 讨论(0)
提交回复
热议问题