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

 
Thank u for u reply. Those are value that passed by cheboxes.The chekboxes has the id of each song.Thanks
 
OK.

I got you now.

Do you have the checkboxes name properly?
Like:

<input type="checkbox" name="sid[]" value="1">THE URL
<input type="checkbox" name="sid[]" value="2">THE URL

If yes, in your PHP:
$url[1] = "THE URL ONE";
$url[2] = "THE URL TWO";
$url[3] = "THE URL THREE";

if (isset($_POST["sid"]))
{
foreach ($_POST["sid"]) AS $value)
$mycontent = $url[$value]."\r\n";
}

OR

if (isset($_GET["sid"]))
{
foreach ($_GET["sid"]) AS $value)
$mycontent = $url[$value]."\r\n";
}

then,

$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";
}
 
Thanks woddy for your helpfull reply . I tried to run the script but i get this error :



Code:
Notice: Undefined variable: mycontent in c:\inetpub\[URL unfurl="true"]wwwroot\php\ram3.php[/URL] on line 19
ERROR IN WRITING TO FILE 
[code]

[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]


if (isset($_GET["sid"]))
{
   foreach ($_GET["sid"]  AS $value )
      $mycontent = $url[$value]."\r\n";
}
 

$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";
}

?>


I called the script this way :


but when i see the ram.ram file i find it empty. I be happy if u help me fix this error.Thanks
 
Thanks again woody . i made the changes but this time it does not say where is the error but it says error writing to the file. All the permetions are ok but still i get this massage: ERROR IN WRITING TO FILE .
The created ram.ram file also is empty!!

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"]))
{
   $allsid = explode (",",$_GET["sid"]);
   foreach ($allsid AS $value)
       if ($value)
           $mycontent = $url[$value]."\r\n";
}

$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";
}

?>

calling method :

 
What about change this:
$handle = fopen ("ram.ram","w+");
to
$handle = fopen ("ram.ram","a");
 
This is most likely a permission problem. The directory where the script is creating the file need to have it's protect string set so that process running the web server can write to it. Remember the when your script is executed by the webserver it is not running under your userid, but under one with minimal privleges.

Ken
 
Thanks kenrbnsn. Well i do not think it is permission problem since i run this script in the same directory and it workes fine!!

Code:
<?php
$fp = fopen( "names.txt" , "w" );
$inputString = 'Some text';
fwrite( $fp, $inputString );
?>
 
Do you run them both from a browser window. If you're not invoking the second script from a browser window, try it and see if it will write the file.

Ken
 
Yes i do rung them from browser. The first one does not write to ram.ram file and gives error. The second one gives no error and write to name.txt successfully!!I even tried to change ram.ram to ram.txt and i got same error.Thanks
 
well i used w+ in the script that creates ram.ram file. Well the name.text i created it but even if i delete it the script makes one for me.Thanks
 
I deleted ram.ram file and put W for the ram.ram and i got same error and next time i used a and same error!!

$handle = fopen ("ram.ram","a");
$handle = fopen ("ram.ram","w");
 
Wow. This is so funny.
if you do this:
echo $mycontent;

is there output in there?
 
Many thanks for u reply. I tried it but no output!!! is there any thing wrong with the way i call the script?Thanks


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"]))
{
   $allsid = explode (",",$_GET["sid"]);
   foreach ($allsid AS $value)
       if ($value)
           $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";
}

?>
 
Try this.
This works on my machine.

<?php
$url[1] = "$url[2] = "$url[3] = "

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

$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";
}
?>
 
Thanks for u reply. It does not work in my system! could u guys tell me how to set up permetions. I want to crate another folder and put that in set new permetion on it.Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top