我使用以下代码,但是当目标图像不是 jpg 时会发生什么?如何确保正确保存任何格式?
myimage
将是myimage[$i]
因为我会保存很多图像。
$content = file_get_contents("http://anothersite/images/goods.jpg");
file_put_contents(YOUR_DIRECTORY."myimage.jpg",$content);
我使用以下代码,但是当目标图像不是 jpg 时会发生什么?如何确保正确保存任何格式?
myimage
将是myimage[$i]
因为我会保存很多图像。
$content = file_get_contents("http://anothersite/images/goods.jpg");
file_put_contents(YOUR_DIRECTORY."myimage.jpg",$content);
您可以使用以下方式从源路径获取扩展名pathinfo
:
$info = pathinfo("http://anothersite/images/goods.jpg");
$destination = YOUR_DIRECTORY . "myimage.{$info['extension']}";