I use the following code, but what happens when the target image is not a jpg ? How can I make sure that any format will be saved correctly?
myimage
will be myimage[$i]
because I will save a lot of images.
$content = file_get_contents("http://anothersite/images/goods.jpg");
file_put_contents(YOUR_DIRECTORY."myimage.jpg",$content);
You can get the extension from the source path using pathinfo
:
$info = pathinfo("http://anothersite/images/goods.jpg");
$destination = YOUR_DIRECTORY . "myimage.{$info['extension']}";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.