PHP: fopen error handling

后端 未结 4 864
天涯浪人
天涯浪人 2021-02-05 03:33

I do fetch a file with

$fp = fopen(\'uploads/Team/img/\'.$team_id.\'.png\', \"rb\");
$str = stream_get_contents($fp);
fclose($fp);

and then the

4条回答
  •  醉酒成梦
    2021-02-05 04:36

    You can use the file_exists() function before calling fopen().

    if(file_exists('uploads/Team/img/'.$team_id.'.png')
    {
        $fp = fopen('uploads/Team/img/'.$team_id.'.png', "rb");
        $str = stream_get_contents($fp);
        fclose($fp);
    }
    

提交回复
热议问题