Question

I'm working on a little Project to give some audio data a web interface. I'm reading the content of existing folders with PHP.

Here's my PHP Code:

<?php
$mp3folder = 'mp3/';
$oggfolder = 'ogg/';
$mp3files = glob($mp3folder.'*.mp3');
$oggfiles = glob($oggfolder.'*.ogg');
echo '
<script type="text/javascript">
    $(document).ready(function(){
    new jPlayerPlaylist({
        jPlayer: "#jquery_jplayer_1",
        cssSelectorAncestor: "#jp_container_1"
    }, [';


for ($i=0; $i<count($mp3files); $i++) {
    $namerr[$i] = substr($oggfiles[$i],strlen($oggfolder),strpos($oggfiles[$i], '.')-strlen($oggfolder));
    echo '{'."\n";
    echo 'title:"'.$namerr[$i].'",'."\n";
    echo 'mp3:"'.$mp3files[$i].'",'."\n";
    echo 'ogg:"'.$oggfiles[$i].'"'."\n";
    echo '},'."\n";
}
echo '
    ], {
        swfPath: "../../_res/jplayer",
        supplied: "ogg, mp3",
        wmode: "window",
        smoothPlayBar: true,
        keyEnabled: true
    });
});
</script>';

?> 

I have directory structure built like this:

AUDIO
 -> index.php
 -> OGG
   -> SONG#1.ogg
   -> SONG#n.ogg
   -> SONG FUN. ogg
 -> MP3
   -> SONG#1.mp3
   -> SONG#n.mp3
   -> SONG FUN.mp3

The php code above successfully reads the audio files and build a list out of it, so jPlayer can read them and show playlists out of it.
Problem is: jPlayer won't read the audio files, when the file name contains a "#" sign. When I try to play "SONG #1.mp3" and then look at the debugger in Chromium it says "File SONG " not found, while it normally outputs something like "File 'SONG FUN.mp3' successfully read".

So my conclusion is that PHP has some kind of problem reading file names that contain a "#".

Or could jPlayer be the problem here?

BTW: this is my first PHP Project, so please be indulgent if there are many mistakes. I'm sure there are different and much better ways to approach this. But I'm a learner.

regards!

Was it helpful?

Solution

Thank You to everyone who helped me on this! Especially Thanks to @Wrikken

I guess I finally figured it out: when I used urlencode() to transform the URLs into a proper form, i had the problem that spaces where converted to + signs where they should rather be transformed into %20. That is - as I understand it - mainly because of the fact that urlencode() is used for queries, so things like index.php?search=Hello+World.

The Solution was to use rawurlencode() instead.

So the Part of code in question now looks like this:

for ($i=0; $i<count($mp3files); $i++) {
$namerr[$i] = substr($oggfiles[$i],strlen($oggfolder),strpos($oggfiles[$i], '.')-strlen($oggfolder));
echo '{'."\n";
echo 'title:"'.$namerr[$i].'",'."\n";
echo 'mp3:"'.dirname($mp3files[$i]).'/'.rawurlencode(basename($mp3files[$i])).'",'."\n";
echo 'ogg:"'.dirname($oggfiles[$i]).'/'.rawurlencode(basename($oggfiles[$i])).'",'."\n";
echo '},'."\n";
}

Thanks for all the good comments!

OTHER TIPS

jPlayer i sa jquery based application. It treats the filenames you output as actual URLs. In the case of URLs, a hashtag denotes a local ID which is not part of the filename. For example http://www.example.com/dir/file#id would return only "file" as the filename, not including the #id!

So your problem can be seen in two ways:

  1. It's caused by alimitation in jPlayer, which in turn is caused by a limitation in the definition of an URL, or
  2. it's caused by you using a # in a place where it's not allowed.

Since you can't change the way URLs are defined, you'll have to change your filenames not to include hashtags.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top