Reputation: 1
<audio controls>
<source src="test.mp3" type="audio/mpeg">
</audio>
I want to display audio tag only if audio file exists . Please help me to resolve this issue
Upvotes: 0
Views: 2226
Reputation: 1656
You need to check file exists
<?php
if (file_exists('test.mp3')) {
?>
<audio controls>
<source src="test.mp3" type="audio/mpeg">
</audio>
<?php } ?>
Upvotes: 0
Reputation: 682
Make an ajax request to the audio file you need.The response will let you know if the file exists or not
$.ajax({
url:'test.mp3',
type:'HEAD',
error: function()
{
//file does not exist
},
success: function()
{
//file exists
}
});
Upvotes: 1