Urlencode and file_get_contents

后端 未结 2 736
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 04:00

We have an url like http://site.s3.amazonaws.com/images/some image @name.jpg inside $string

What I\'m trying to do (yes, there is a whitesp

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 04:10

    The URL you have specified is invalid. file_get_contents expects a valid http URI (more precisely, the underlying http wrapper does). As your invalid URI is not a valid URI, file_get_contents fails.

    You can fix this by turning your invalid URI into a valid URI. Information how to write a valid URI is available in RFC3986. You need to take care that all special characters are represented correctly. e.g. spaces to plus-signs, and the commercial at sign has to be URL encoded. Also superfluous whitespace at beginning and end need to be removed.

    When done, the webserver will tell you that the access is forbidden. You then might need to add additional request headers via HTTP context options for the HTTP file wrapper to solve that. You find the information in the PHP manual: http:// -- https:// — Accessing HTTP(s) URLs

提交回复
热议问题