我通过使用以下代码行从我的PHP服务器上检索图像放置我的PHP服务器API
$response = file_get_contents($url);
我也将这个文件写到服务器上的文件夹中,如下所示:(返回的文件是二进制文件,而不是图像文件)
file_put_contents($folderPath,$response);
如何找到我读入$ response的文件的文件扩展名?
我尝试过以下方法:
$response = file_get_contents($url);
$size = getimagesize($response);
$extension = image_type_to_extension($response)
尝试pathinfo
http://php.net/manual/en/function.pathinfo.php
它应该会帮助你
[编辑]由于您的图像以二进制形式返回,请使用php的getimagesizefromstring http://php.net/manual/en/function.getimagesizefromstring.php
它将返回您需要的所有详细信息。
Google不会返回带后缀的文件。尝试使用mime_content_type($response)
,然后解析响应以找出正确的后缀
您可以使用pathinfo获取扩展名。
$extension = pathinfo($response, PATHINFO_EXTENSION);