I'm writing a document that automatically lists images and ringtones. It works great, but I'm also trying to add a Preview option for the midi ringtones and that is where my problem is coming in. I'm using a javascript popup that jumps up when the user clicks the preview link, its a dynamically created document that display the embedded midi file, well, its supposed to...
Here, check out my code:
//////This is the javascript function I'm using to call the popup/////
<script language ="javascript">
function dirtypop()
{
var generator=window.open('','name','height=50,width=200');
generator.document.write('<link rel="stylesheet" href="http://jmcivor.com/portal/themes/Bitrate2/style/styleNN.css"
type="text/css">');
generator.document.write('<embed src="$file" height=40 width=160>');
generator.document.write('<p><center><a href="javascript:self.close()">Close</a> this window.</center></p>');
generator.document.write('</body></html>');
generator.document.close();
}
</script>
/////////////////////////////////////////////////////////////////
<?php
$handle=opendir("./");
$n = 0;
$filecount;
while (false !== ($file = readdir($handle)))
{
$ext = strtolower(strstr($file, '.'));
///////////////////////////////////////////////////
//count files//////////////////////////////////////
///////////////////////////////////////////////////
if ($ext == ".jpeg")
{
$n++;
$filecount=$filecount+1;
}
if ($ext == ".bmp")
{
$n++;
$filecount=$filecount+1;
}
if ($ext == ".jpg")
{
$n++;
$filecount=$filecount+1;
}
if ($ext == ".gif")
{
$n++;
$filecount=$filecount+1;
}
if ($ext == ".imy")
{
$n++;
$filecount=$filecount+1;
}
if ($ext == ".emy")
{
$n++;
$filecount=$filecount+1;
}
if ($ext == ".midi")
{
$n++;
$filecount=$filecount+1;
}
if ($ext == ".mid")
{
$n++;
$filecount=$filecount+1;
}
if ($ext == ".mp3")
{
$n++;
$filecount=$filecount+1;
}
if ($ext == ".wav")
{
$n++;
$filecount=$filecount+1;
}
if ($ext == ".zip")
{
$n++;
$filecount=$filecount+1;
}
if ($ext == ".thm")
{
$n++;
$filecount=$filecount+1;
}
}
//Post FileCount at top of page////////////////////
echo "<body>$filecount Files Found<br><br></body>";
///////////////////////////////////////////////////
///////////////////////////////////////////////////
//List Files///////////////////////////////////////
///////////////////////////////////////////////////
$handle=opendir("./");
$n = 0;
while (false !== ($file = readdir($handle)))
{
$ext = strtolower(strstr($file, '.'));
if ($ext == ".bmp")
{
echo " <a href='$file'>$file<br><img src='$file'></a><br><br>";
$n++;
}
if ($ext == ".jpeg")
{
echo " <a href='$file'>$file<br><img src='$file'></a><br><br>";
$n++;
}
if ($ext == ".jpg")
{
echo " <a href='$file'>$file<br><img src='$file'></a><br><br>";
$n++;
}
if ($ext == ".gif")
{
echo " <a href='$file'>$file<br><img src='$file'></a><br><br>";
$n++;
}
if ($ext == ".imy")
{
echo " <a href='$file'>$file</a><br>";
$n++;
}
if ($ext == ".emy")
{
echo " <a href='$file'>$file</a><br>";
$n++;
}
if ($ext == ".midi")
{
echo " <a href='$file'>$file</a><br>";
$n++;
}
///////This section is the culprit that refuses to work properly//////
if ($ext == ".mid")
{
echo " <a href='$file'>$file</a> | <a href='javascript:dirtypop();'>Preview Ringtone</a><br>";
$n++;
}
/////////////////////////////////////////////////////////////////////////////////
if ($ext == ".mp3")
{
echo " <a href='$file'>$file</a><br>";
$n++;
}
if ($ext == ".wav")
{
echo " <a href='$file'>$file</a><br>";
$n++;
}
if ($ext == ".zip")
{
echo " <a href='$file'>$file</a><br>";
$n++;
}
if ($ext == ".thm")
{
echo " <a href='$file'>$file</a><br>";
$n++;
}
}
echo("\n");
closedir($handle);
?>
Now, this whole document works great except the popup part, it pops up, looks all pretty and perfect, but it refuses to link to the variable specified in the source called "$file". Everything else accepts this variable and uses it properly accept the popup one (you'll notice it 2/3rds the way down the source in the .mid area.) It pops up the window perfectly but wont link to the midi file, When I ViewSource with internet explorer on the popup window it shows me that the embed option is actually trying to embed $file and not the filename held in $file, it is assuming that $file is the actual file name. To see what I mean, just paste this source code into notepad and save it as a php document, then put it in the same folder as a midi file (or 2 or 3 or whatever) and it will give you 2 options for each song, download, or preview, click preview, you'll get the popup, then right click and view source, you'll see what I mean.
Please help! Im so stumped!