Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function loadYandexImage($url, $savePath)
- {
- $imageFormats = [
- 'image/jpeg' => 'jpeg',
- 'image/jpg' => 'jpg',
- 'image/png' => 'png',
- 'image/gif' => 'gif',
- 'image/bmp' => 'bmp',
- ];
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $server_output = curl_exec ($ch);
- $yandexData = curl_getinfo($ch);
- $extension = (isset($yandexData['content_type']) && $yandexData['content_type'] && isset($imageFormats[$yandexData['content_type']])) ? $imageFormats[$yandexData['content_type']] : 'png';
- $realImagePath = (isset($yandexData['redirect_url']) && $yandexData['redirect_url'] ) ? $yandexData['redirect_url'] : $url;
- return copy($realImagePath, $savePath.'/'.date('d-m-y').'.'.$extension);
- }
- loadYandexImage("https://avatars.mds.yandex.net/get-afishanew/35821/e2a1ae77cd2b19ae9cbe6271b3d6ce5c/960x500", __DIR__);
Add Comment
Please, Sign In to add comment