Skip to content

Instantly share code, notes, and snippets.

@mvrueden
Last active March 8, 2017 21:06
Show Gist options
  • Save mvrueden/76f60224c5f31659a99608d93f165192 to your computer and use it in GitHub Desktop.
Save mvrueden/76f60224c5f31659a99608d93f165192 to your computer and use it in GitHub Desktop.
Simple "server" to serve images for mpod.
<?php
// Simple "server" to serve images for mpod.
// Configure Mpod like this: "host:port/cover.php?get=".
// Simply start it with "php -S 0.0.0.0:port"
// For me "sacad_r" worked best to automatically download covers: "sacad_r ./ 600 cover.jpg"
// See: https://github.com/desbma/sacad
$root = "/var/lib/mpd/music/"; //mpd lib direcotry (must end with /)
// We need at least one parameter
if (sizeof($_GET) >= 1 && array_key_exists("get", $_GET)) {
// get path
$path = $_GET["get"];
$cover = $root . $path;
if (file_exists($cover)) {
header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
header("Content-Type: image/jpeg");
header("Content-Length:" . filesize($cover));
readfile($cover);
die();
} else {
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
die();
}
} else {
header($_SERVER["SERVER_PROTOCOL"] . " 400 Bad Request");
die();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment