mp3list.php
· 969 B · PHP
Raw
<?php
$arr = array();
foreach (iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.', FilesystemIterator::SKIP_DOTS))) as $item => $file) {
$arr[] = $item;
}
sort($arr);
?>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var audio = document.createElement('audio');
$(window).load(function() {
audio.setAttribute('src', '<?php echo reset($arr); ?>');
audio.setAttribute('controls', 'controls');
audio.setAttribute('id', 'audio');
$('body').append(audio);
});
function set_src(filename) {
audio.setAttribute('src', filename);
audio.load();
audio.play();
return false;
}
</script>
</head>
<body>
<ul>
<?php
foreach($arr as $item) {
if (mime_content_type($item) == "audio/mpeg") { ?>
<li><a href="<?php echo $item; ?>" onClick="return set_src('<?php echo $item; ?>');"><?php echo substr($item, 2); ?></a></li>
<?php } }
?>
</ul>
</body>
</html>
| 1 | <?php |
| 2 | $arr = array(); |
| 3 | foreach (iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.', FilesystemIterator::SKIP_DOTS))) as $item => $file) { |
| 4 | $arr[] = $item; |
| 5 | } |
| 6 | sort($arr); |
| 7 | ?> |
| 8 | <html> |
| 9 | <head> |
| 10 | <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> |
| 11 | <script> |
| 12 | var audio = document.createElement('audio'); |
| 13 | $(window).load(function() { |
| 14 | audio.setAttribute('src', '<?php echo reset($arr); ?>'); |
| 15 | audio.setAttribute('controls', 'controls'); |
| 16 | audio.setAttribute('id', 'audio'); |
| 17 | $('body').append(audio); |
| 18 | }); |
| 19 | |
| 20 | function set_src(filename) { |
| 21 | audio.setAttribute('src', filename); |
| 22 | audio.load(); |
| 23 | audio.play(); |
| 24 | return false; |
| 25 | } |
| 26 | </script> |
| 27 | </head> |
| 28 | <body> |
| 29 | <ul> |
| 30 | <?php |
| 31 | foreach($arr as $item) { |
| 32 | if (mime_content_type($item) == "audio/mpeg") { ?> |
| 33 | <li><a href="<?php echo $item; ?>" onClick="return set_src('<?php echo $item; ?>');"><?php echo substr($item, 2); ?></a></li> |
| 34 | <?php } } |
| 35 | ?> |
| 36 | </ul> |
| 37 | </body> |
| 38 | </html> |
| 39 |