Skip to content

Instantly share code, notes, and snippets.

@ArthurHoaro
Created October 17, 2014 12:45
Show Gist options
  • Save ArthurHoaro/2f457bdd415b5eab2524 to your computer and use it in GitHub Desktop.
Save ArthurHoaro/2f457bdd415b5eab2524 to your computer and use it in GitHub Desktop.
Download actual favicon with https://github.com/ArthurHoaro/favicon
<?php
stream_context_set_default(array(
'http' => array(
'method' => 'GET',
'timeout' => 10,
'header' => "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:20.0; Favicon; +https://github.com/ArthurHoaro/favicon) Gecko/20100101 Firefox/32.0\r\n",
)
)
);
/**
* Get feed favicon
*/
$favicon = FAVICON_DIRECTORY . $feed_name . '.ico';
if( (!file_exists($favicon) ) {
$favService = new Favicon();
if( $favUrl = $favService->get($feed_link) ) {
$favRequest = file_get_contents($favUrl);
file_put_contents($favicon, $favRequest['html']);
}
}
if( !file_exists($favicon) || !filesize($favicon) ) {
copy( FAVICON_DIRECTORY . FAVICON_DEFAULT, $favicon );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment