I am designing a site that displays the icon of any song, on the server. I have created a php file that returns the image of the song, if it exists. My code in HTML:
<img src="/image.php?song=SongName" width="100" height="100">
If the given song has a cover icon, then the img element shows the icon. If it doesn't, I get an empty 100x100 img box.
Now, I want to specify in javascript, if the url address: '/image.php?song=SongName' returns null (if there is not an image cover on the song), in order to hide the img. How to achieve it?
Thanks.
PS. The code I've tried so far (there's a bit of php for the img url formation):
var picElement = document.getElementById("picture");
picElement.src = "/image.php?song=$nameFile";
if(picElement.src == null){
picElement.style.display = "none";
}else if(picElement.src !=null){
picElement.src = "/image.php?song=$nameFile";
picElement.style.height = "20vh";
picElement.style.width = "20vh";
picElement.style["boxShadow"] = "3px 3px 10px 1px #e2b674";
}
The php code under image.php:
<?PHP
$song= $_GET["song"];
require_once("getID3-1.9.15/getid3/getid3.php");
$Path= .$song.".mp3";
$getID3 = new getID3;
$OldThisFileInfo = $getID3->analyze($Path);
if(isset($OldThisFileInfo['comments']['picture'][0]))
{
header('Content-Type: ' . $OldThisFileInfo['comments']['picture'][0]['image_mime']);
echo $OldThisFileInfo['comments']['picture'][0]['data'];
die;
}?>