我使用以下几行代码从我的PHP服务器上的google places 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)发布于 2018-03-04 03:42:23
尝试pathinfo
http://php.net/manual/en/function.pathinfo.php
它应该对你有帮助
编辑,因为你的图片是以二进制格式返回的,然后使用php的getimagesizefromstring字符串http://php.net/manual/en/function.getimagesizefromstring.php
它将返回您需要的所有详细信息。
发布于 2018-03-04 03:47:26
Google不会返回带有后缀的文件。尝试mime_content_type($response),然后解析响应以找出正确的后缀
发布于 2018-03-04 03:43:10
您可以使用pathinfo来获取扩展。
$extension = pathinfo($response, PATHINFO_EXTENSION);https://stackoverflow.com/questions/49088364
复制相似问题