probleming writing dynamic value into text file in php

Joined
Jun 30, 2005
Messages
59
Reaction score
0
problem writing dynamic value into text file in php

Hi all. i have a little problem writing dynamic value to a ram.txt file. I want write the following infor int a text file:
Code:
<player showDisplay="yes" showPlaylist="yes" autoStart="yes">
  <song path="[B][url]http://localhost/flash_mp3_player/mp3/08[/url] - Track 8.mp3[/B]" title="[B]tajik[/B]" /> 
  <song path="[B][url]http://localhost/flash_mp3_player/mp3/13[/url] - Gar Aya.mp3[/B]" title="[B]gar aya[/B]" /> 
  </player>
The song path for each song id i pass.
<player showDisplay="yes" showPlaylist="yes" autoStart="yes">
and
</player>
are written once at the start and end of the text file.The title is just the name of song without .mp3 extention.
Currently when i call the code like this:
http://localhost/player/ram4.php?sid=1,2,
the only information which is get written to text file is the url but i want write song path and title in above mention format.
I be happy if an expert help me here.Thanks
ram4.php code
Code:
<?php

[B]$url[1] = "[url="http://localhost/flash_mp3_player/mp3/08"]http://localhost/flash_mp3_player/mp3/08[/url] - Track 8.mp3";
$url[2] = "[url="http://localhost/flash_mp3_player/mp3/13"]http://localhost/flash_mp3_player/mp3/13[/url] - Gar Aya.mp3";
$url[3] = "[url="http://localhost/flash_mp3_player/mp3/Soroush"]http://localhost/flash_mp3_player/mp3/Soroush[/url] - Yeh Donya - 02 Shoghe Nafas.mp3";[/B]
$mycontent = "";
if (isset($_GET["sid"]))
{
   $allsid = explode (",",$_GET["sid"]);
   $mycontent = array();
   foreach ($allsid AS $value)
	  $mycontent[] = $url[$value];
}
echo $mycontent;
[B]$handle = fopen ("ram.txt","w+");[/B]
if ($handle)
{
  if (fwrite ( $handle,implode("\r\n",$mycontent)."\r\n") )
  {
	  echo "FILE IS WRITTEN SUCCESSFULLY";
  } else
  {
	   echo "ERROR IN WRITING TO FILE";
  }
  fclose ($handle);
} else
{
	  echo "ERROR IN OPENING FILE";
}
require 'config.txt';
?>
 
Last edited:
I haven't tested this but perhaps it'll work... or something similar

Code:
$url[1] = "http://localhost/flash_mp3_player/mp3/08 - Track 8.mp3";
$url[2] = "http://localhost/flash_mp3_player/mp3/13 - Gar Aya.mp3";
$url[3] = [url="http://localhost/flash_mp3_player/mp3/Soroush - Yeh Donya - 02 Shoghe Nafas.mp3"]http://localhost/flash_mp3_player/mp3/Soroush - Yeh Donya - 02 Shoghe Nafas.mp3[/url];
 
if (isset($_GET["sid"])) {
 // continue
} else {
 return;
}
 
$handle = fopen ("ram.txt","w+");
if ($handle)
{
  $allsid = explode (",",$_GET["sid"]);
  foreach ($allsid AS $value) {
	fwrite ($handle, $url[$value]); 
  }
  fclose ($handle);
}
 
require 'config.txt';
?>

there's no error checking on the array index or other checking but so long as it's just for you to use at home it should be ok

Sil
 
Back
Top