Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8459353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:18:30+00:00 2026-06-10T13:18:30+00:00

I’m trying to make a script that will generate a .WPL file. The script

  • 0

I’m trying to make a script that will generate a .WPL file. The script scans the folder for all .mp3 files, and includes them in the .wpl file. However it doesn’t seem to work, as Windows media player gives me an error that the file is corrupted.

What is wrong with the code? 🙂

    $ourFileName = "Playlist.wpl";
    $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
    echo "Created the playlist <br />";
    $firsthalf = "
    <?wpl version='1.0'?>
        <smil>
            <head>
                <meta name='Generator' content='Microsoft Windows Media Player -- 12.0.9200.16384'/>
                <meta name='IsNetworkFeed' content='0'/>
                <title>Playlist</title>
            </head>
        <body>
            <seq>";
    $secondhalf = "
        </seq>
        </body>
    </smil>
    ";

    fwrite($ourFileHandle, $firsthalf);

    foreach (glob("*.mp3") as $filename) {
        fwrite($ourFileHandle, "<media src='".$filename."'/>");     
    }       

    fwrite($ourFileHandle, $secondhalf);
    fclose($ourFileHandle);

EDIT: The generated .wpl file looks like this:

    <?wpl version='1.0'?>
        <smil>
            <head>
                <meta name='Generator' content='Microsoft Windows Media Player -- 12.0.9200.16384'/>
                <meta name='IsNetworkFeed' content='0'/>
                <title>Playlist</title>
            </head>
        <body>
            <seq><media src='FIRST SONG.mp3'/><media src='SECOND SONG.mp3'/>
        </seq>
        </body>
    </smil>

EDIT2: The songs are in the same folder as the playlist file.
EDIT3: I’m using the newest Windows Media Player which is included in windows 8 RTM.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:18:32+00:00Added an answer on June 10, 2026 at 1:18 pm

    Why not use PHP to create the wpl file dynamically, I quickly put together this function, perhaps its of some interest, output into a file, browser or force download/send the file to the user.

    <?php
    create_playlist('./', "Playlist.wpl",'save');
    
    /**
     * Using SimpleXMLElement create wmp playlist
     *
     * @param string $path_to_files - Pathe to mp3 files
     * @param string $save_path - path to save your xml
     * @param string $handle - download || save 
     */
    function create_playlist($path_to_files, $save_path=null, $handle='download'){
    
        $xml = new SimpleXMLElement('<?wpl version="1.0"?><smil/>');
        $node = $xml->addChild('head');
    
        $meta = $node->addChild('meta', '');
        $meta->addAttribute('name', 'Generator');
        $meta->addAttribute('content', 'Microsoft Windows Media Player -- 12.0.9200.16384');
    
        $meta = $node->addChild('meta', '');
        $meta->addAttribute('name', 'IsNetworkFeed');
        $meta->addAttribute('content', '0');
    
        $node->addChild('title', 'Playlist');
    
        $body = $xml->addChild('body');
        $seq = $body->addChild('seq');
    
        foreach (glob($path_to_files."*.mp3") as $filename) {
            $media = $seq->addChild('media', "");
            $media->addAttribute('src', realpath($filename));
        }
    
        ob_start();
        echo $xml->asXML();
        $return = ob_get_contents();
        ob_end_clean();
        $return = trim(str_replace(array('<?xml version="1.0"?>','></media>','></meta>'),array('','/>','/>'),$return));
    
        if($handle == 'download'){
            //Force a download
            header('Content-Description: File Transfer');
            header('Content-Type: application/vnd.ms-wpl');
            header('Content-Disposition: attachment; filename=our_playlist.wpl');
            header('Content-Transfer-Encoding: binary');
            header('Content-Length: ' . sprintf("%u", strlen($return)));
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Expires: 0');
            header('Pragma: public');
            exit($output);
        }elseif($handle == 'save'){
            file_put_contents($save_path, $return);
            return true;
        }else{
            exit($return);
        }
    }
    
    /**
     * Result
     * 
    <?wpl version="1.0"?>
    <smil>
       <head>
        <meta name="Generator" content="Microsoft Windows Media Player -- 12.0.9200.16384"/>
        <meta name="IsNetworkFeed" content="0"/>
        <title>Playlist</title>
       </head>
    
       <body>
        <seq>
            <media src="C:\xampp\htdocs\test.mp3"/>
            ...
            ...
        </seq>
       </body>
    </smil>
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.