Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write song URL to .ram text file

Status
Not open for further replies.

JASONE25

Technical User
Jun 23, 2005
54
NL
Hi every body. I am trying to write a php script that once i call it like this"


It goes and writes the song URL to ram.ram file and open the file for me.
I only want to pass sids such as 1,2,...(song url inside the ram.php script)But i do not know how to do this. I be happy if some expert show me how to do this.Thanks


Inside ram.ram file

 
I think the main reason for you is not the permission problem.
But it is due to the empty text of mycontent.
If we could do the debugging.

if (isset($_GET["sid"]))
{
echo ($_GET["sid"])."<BR>";
$allsid = explode (",",$_GET["sid"]);
echo "<pre>";
print_r($allsid);
echo "</pre>";
foreach ($allsid as $value)
{
echo "VALUE : " .$value."<BR>";
if ($value != "")
{
echo "URL : " .$url[$value]."<BR>";
$mycontent .= $url[$value]."\r\n";
}
}
}
 
The problem can't be then lack of content in his variable, if that were true, he would end up with an empty file, not with the error he is recieving.

To the OP: What type of machine are you running on and which webserver?

I just saw why your $mycontent is empty. The URL you're specifying is
Code:
[URL unfurl="true"]http://localhost/php/ram3.php?[/URL][b][red]sids[/red][/b]=1,2
yet in your code
Code:
if (isset($_GET["sid"]))
you're looking for the contest of [red]sid[/red]. Either change all references of $_GET['sid'] to $_GET['sids'] or change your URL to use "?sid=1,2".

Also, in your original code you have
Code:
   foreach ($allsid AS $value)
       if ($value)
           $mycontent = $url[$value]."\r\n";
That will result in $mycontent containing only the last value. Here's how I would write it:
Code:
   $mycontent = array();
   foreach ($allsid AS $value)
      $mycontent[] = $url[$value];
The in your fwrite statement, I would use:
Code:
fwrite ( $handle,implode("\r\n",$mycontent)."\r\n")

Ken
 
Wooody thank mate. I tried the debug nothing out on the scree. I tried both with out write to file block and with it. in both case no out put on the screen but with later one only that strange errorr!


Code:
<?php


$url[1] = "[URL unfurl="true"]http://localhost/songs/g1.rm";[/URL]
$url[2] = "[URL unfurl="true"]http://localhost/songs/g2.rm";[/URL]
$url[3] = "[URL unfurl="true"]http://localhost/songs/g3.rm";[/URL]


$mycontent = "";
if (isset($_GET["sid"]))
{
   echo ($_GET["sid"])."<BR>";
   $allsid = explode (",",$_GET["sid"]);
   echo "<pre>";
   print_r($allsid);
   echo "</pre>";
   foreach ($allsid as $value)
   {
      echo "VALUE : " .$value."<BR>";
      if ($value != "")
      {
           echo "URL : " .$url[$value]."<BR>";
           $mycontent .= $url[$value]."\r\n";
      }
    }
}

echo $mycontent;

$handle = fopen ("ram.ram","w+");
if ($handle)
{
  if (fwrite ( $handle,$mycontent) )
  {
      echo "FILE IS WRITTEN SUCCESSFULLY";
  } else
  {
       echo "ERROR IN WRITING TO FILE";
  }
  fclose ($handle);
} else
{
      echo "ERROR IN OPENING FILE";
}

?>
 
OK. I think Ken is right.
Because you are calling this:

You should have:
$mycontent = "";
if (isset($_GET["sids"]))
{
$allsid = explode (",",$_GET["sids"]);
foreach ($allsid as $value)
if ($value != "")
$mycontent .= $url[$value]."\r\n";
}

:)
 
And Ken, when you have emptry string, the new file won't be created at all. I have experienced that many many times.
At least a " " needs to be in the string to write.
 
Thanks, I didn't know that. I'll give it a try and see what happens.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top