Jump to content

PHP file write question PLEASE HELP!


robmarston

Recommended Posts

Is it possible to use PHP to add/remove text from a flat file?

 

Basically, what I'm attempting to do is have users click to add/remove (manage) songs from a dynamically generated XML playlist.

I've used the file write command to generate a successful XML playlist file, but every time the form data is submitted, it overwrites the entire file. 

I want the user to be able to not only add songs, but remove old ones as well.

 

I've considered simply adding or removing songs from a database table, but how then would I generate the playlist from database information?

 

PLEASE HELP!

 

Please send help to: [email protected] -

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/61415-php-file-write-question-please-help/
Share on other sites

Yes, see the filesystem functions section of the PHP manual for a plethora of functions and examples.

 

You can add to a file without overwriting the existing contents using an "append" mode instead of "write."  Or you can read the file into memory, alter it, and write it out, overwriting the old version.

Actually, depending upon how expansive your information is going to become, you might consider using a database anyway.  This seems like the kind of application that would need one...that way you could relationally store information about a particular item's author, genre, whatever...As for generating a playlist out of database information...You could technically query your database, and then output the queried data in to a flat file for use as a playlist:

 

$q = "SELECT * FROM tbl_songs";

 

$q_result=mysql_query($q);

 

 

//Open or create flat playlist file.

$f_handle=fopen("playlist", "w+");

 

 

 

while ($q_array=mysql_fetch_assoc($q_result))

 

            {

                //Feed the contents of the SQL query in to variable

                $content=$content.q_array[songName];

 

 

              }

 

//Write the final contents out to the flat file.

fwrite($f_handle,$contents);

 

 

Sorry if I'm misunderstanding you here!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.