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

  • SEARCH
  • Home
  • 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 8349155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:54:40+00:00 2026-06-09T07:54:40+00:00

The following code generates a new php file playlist.php which contains the code as

  • 0

The following code generates a new php file playlist.php which contains the code as in $start $result variable

$path = "./files/";
$path2="http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/files/";
//echo $path2;
$folder = opendir($path);
$start="<asx version='3.0'>\n<title>Example ASX playlist</title>";
$Fnm = "./playlist.php";
$inF = fopen($Fnm,"w");
fwrite($inF,$start."\n");
while( $file = readdir($folder) ) {
 if (($file != '.')&&($file != '..')&&($file != 'index.htm')){
 $result="<entry>\n<title>$file</title>\n<ref href='$path2$file'/>\n<param name='image'     value='preview.jpg'/>\n</entry>\n";
     fwrite($inF,$result);
 }
}
fwrite($inF,"</asx>");
closedir($folder);
fclose($inF);

I want to generate the same code in the same file which contains this code on a specified line number
is this possible ?

The above php script generates the following code on a new file
http://tinypaste.com/ff242cd6

  • 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-09T07:54:41+00:00Added an answer on June 9, 2026 at 7:54 am

    Here’s how to append:

    $path = "./files/";
    $path2="http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/files/";
    //echo $path2;
    $folder = opendir($path);
    $start="<asx version='3.0'>\n<title>Example ASX playlist</title>";
    $Fnm = "./playlist.php";
    // build content
    $fileContent=$start.'/n';
    
    while( $file = readdir($folder) ) {
     if (($file != '.')&&($file != '..')&&($file != 'index.htm')){
     $result="<entry>\n<title>$file</title>\n<ref href='$path2$file'/>\n<param name='image'     value='preview.jpg'/>\n</entry>\n";
         //append to content
    $fileContent .= $result;
     }
    }
         //append to content
    $fileContent .= "</asx>";
    
    // append to file and check status
    if ( file_put_contents(__FILE__ , $fileContent , FILE_APPEND) === false )
    {
    
    echo "failed to put contents in ".__FILE__."<br>";
    
    }
    

    That should do it…

    EDIT:

    Okay, before I get into it, you should first take a look at some basic PHP tutorials which can be found all over the net.

    SO, instead of writing the content to the file, just echo it, and add your dynamic stuff while you echo:

    $title='the title of your playlist';
    
    $start="<asx version='3.0'>\n<title>".$title."</title>/n";
    
    while( $file = readdir($folder) ) {
     if (($file != '.')&&($file != '..')&&($file != 'index.htm')){
     $result="<entry>\n<title>$file</title>\n<ref href='$path2.$file'/>\n<param name='image'     value='preview.jpg'/>\n</entry>\n";
    }
    }
    
    $endCont = $start.$result."</asx>";
    
    echo $endCont;
    

    I created a new variable called $title. The value of that will be the title generated in the output. You can do this with other tags too like you’ve done with <entry>\n<title>$file</title>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One of the following pieces of code generates a memory leak, any idea which
I'm building a category manager via database. The following PHP generates the code I'll
I have a script that generates a csv file using the following code: header('Content-type:
I'm new to PHP. I'm using the following code to generate an excel sheet
The following code generates an error: @Html.ActionLink(Title, action, new { id=1 }, new {
The following code generates a MS Word document in portrait format. But I need
The following code generates a FileNotFoundException (using .NET 2.0): using System; using System.Collections.Generic; using
I have the following code (generates a quadratic function given the a, b, and
I don't understand why the following code generates a warning. interface Generic<T> { }
The following code snippet generates some warning messages when compiling: Cluster& Myclass::getCluster(const Point &p)

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.