PHP: fopen error handling

后端 未结 4 909
天涯浪人
天涯浪人 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:17

    [{"message":"Warning: fopen(uploads\/Team\/img\/1.png): failed to open stream: No such file or directory in C:\...
    

    the error is clear: you've put the wrong directory, you can try what you whant but it'll not work. you can make it work with this:

    1. take your file and put it in the same folder of your php file (you'll be able to move it after don't worry, it's about your error) or on a folder "higher" of your script (just not outside of your www folder)
    2. change the fopen to ('./$team_id.'png',"rb");
    3. rerun your script file

    don't forget this : you can't access a file that is'nt in your "www" folder (he doesn't found your file because he give you her name: the name come from the $team_id variable)

提交回复
热议问题