www.webdeveloper.com
Results 1 to 6 of 6

Thread: PHP....Dynamic asx file

  1. #1
    Join Date
    Aug 2010
    Posts
    58

    Angry PHP....Dynamic asx file

    Hello,
    I wish to create a dynamic asx file which lists all the mp3 files in a directory...
    This is then used in a html file as the source of an "<embed>" tag...
    The html file does not open the asx playlist at all and I dont know what the problem is.... I have altered my http.conf file to add .asx as a php extension..
    Here is the content of my asx files
    Thanks



    PHP Code:
    <?php
    header
    ("Content-Type: video/x-ms-asf;");

    // setting the directory to search for mp3 files

    // reading the directory and inserting the mp3 files in the playlist array
    $playlist = array();
    $fdir scandir('.');
    foreach(
    $fdir as $i){

    // if a .mp3 string is found, add the file to the array


    if (strpos(strtolower($i),".mp3") !== false){
    $playlist[] = $i;}




    #sort() or shuffle()

    }


    echo 
    "<asx version="3.0">";
    foreach(
    $playlist as $i){
    echo 
    "<ENTRY>\n";
    echo 
    "<REF HREF=http://localhost/music/".$i." />\n";
    echo 
    "</ENTRY>\n\n";
    }
    echo 
    "</asx>"


    ?>

  2. #2
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    try properly escaping your version number:

    PHP Code:
    <?php echo "<asx version="3.0">";
    should probably be:

    PHP Code:
    <?php echo "<asx version=\"3.0\">";
    does the .asx file open in a browser by itself? ie. as the raw XML content?

  3. #3
    Join Date
    Aug 2010
    Posts
    58
    it opens with a "cannot play" error

    It still doesnt work with : echo "<asp version='3.0'>" ...

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    You also having the same quoting problem here:
    echo "<REF HREF=http://localhost/music/".$i." />\n";

  5. #5
    Join Date
    Aug 2010
    Posts
    58
    i cannot see anything wrong with it... The extra quotes is me joining a string to a variable to another string

  6. #6
    Join Date
    Jan 2009
    Posts
    3,346
    I'm not 100% sure...but it is usually good practice to enclose attributes with quotes.

    As in:
    PHP Code:
    echo "<REF HREF=\"http://localhost/music/".$i."\" />\n"
    Have you taken a look at what the raw output of your script is?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles