所以我得到了一些与一些PHP代码完全不同的东西所以我想要获得的是这个,一个切换链接到同一页面,按下时切换将显示使用PHP生成的链接列表,链接是下载来自服务器的一些文件,提前抱歉使用torrent链接,但我不知道还有什么其他的,我还想提一下,我不是用这些来创建任何类型的非法内容网站,所以这里是html的例子:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function toggle_visibility(id) {
var e = document.getElementById(id);
if (e.style.display == 'block') e.style.display = 'none';
else e.style.display = 'block';
}
</script>
<style>
#foo1 {
list-style-type: none;
padding-bottom:10px;
display: none;
}
#foo2 {
list-style-type: none;
padding-bottom:10px;
display: none;
}
</style>
</head>
<body>
<h3>Programs</h3>
<a href="#" onclick="toggle_visibility('foo1');">Movies</a>
<div id="foo1">
<ul style="padding-bottom:15px;list-style-type: none;">
<li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=http://kickass.to/the-official-uk-top-40-singles-chart-15-06-2014-t9225052.html" onclick="this.color=#FF0000;"> _Movie~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>
</li>
<li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=http://kickass.to/the-official-uk-top-40-singles-chart-15-06-2014-t9225052.html" onclick="this.color=#FF0000;"> _Movie~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>
</li>
<li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=http://kickass.to/the-official-uk-top-40-singles-chart-15-06-2014-t9225052.html" onclick="this.color=#FF0000;"> _Movie~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>
</li>
</ul>
</div>
<br><a href="#" onclick="toggle_visibility('foo2');">Music</a>
<div id="foo2">
<ul style="padding-bottom:15px;list-style-type: none;">
<li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=https://kickass.to/game-of-thrones-s04e10-720p-hdtv-x264-killers-rartv-t9225859.html" onclick="this.color=#FF0000;"> _Muzic~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>
</li>
<li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=http://kickass.to/game-of-thrones-s04e10-720p-hdtv-x264-killers-rartv-t9225859.html" onclick="this.color=#FF0000;"> _Muzic~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>
</li>
<li style="padding-bottom:15px;"><a href="itms-services://?action=download-manifest&url=http://kickass.to/game-of-thrones-s04e10-720p-hdtv-x264-killers-rartv-t9225859.html" onclick="this.color=#FF0000;"> _Muzic~2014-06-16-1808-name-muzic--1.0.1-4035-g0d107d0~Host</a>
</li>
</ul>
</div>
</body></html>
我现在用PHP做的是:
<?
if (isset($_POST['password']))
{
$password = $_POST['password'];
$goodPass = '******';
if ($password == $goodPass)
$_SESSION['loggedIn']=1;
}
if (!isset($_SESSION['loggedIn']))
showPasswordForm();
else
{
$install_links = getDirectory(".");
rsort($install_links);
$oldPrefix = "";
foreach ($install_links as $key => $val)
{
$strip_val = strip_tags($val);
$prefix = explode("~",$strip_val);
//echo "Prefix:|".$prefix[0]."|</br>";
if (strcmp($prefix[0],$oldPrefix)!=0)
echo <<<EOT </div> <a href='#' onclick="toggle_visibility('".$prefix[0]."');"> "".$prefix[0].""</a><div id="".$prefix[0]."">EOT;
$oldPrefix = $prefix[0];
echo '<li style="padding-bottom:15px">'.$val.'</li><br/>';
}
}
function getDirectory( $path = '.', $level = 0 ){
$echoData = false;
$protocol = isset($_SERVER['HTTPS']) ? "https://" : "http://";
$root_folder_url_prefix = $protocol.".....";
$ignore = array( 'cgi-bin', '.', '..','WHat.app.dSYM' );
// Directories to ignore when listing output. Many hosts
// will deny PHP access to the cgi-bin.
$dh = @opendir( $path );
// Open the directory to the handle $dh
$install_links = array();
while( false !== ( $file = readdir( $dh ) ) ){
// Loop through the directory
if( !in_array( $file, $ignore ) ){
// Check that this file is not to be ignored
$spaces = str_repeat( ' ', ( $level * 4 ) );
// Just to add spacing to the list, to better
// show the directory tree.
if( is_dir( "$path/$file" ) ){
// Its a directory, so we need to keep reading down...
if ( $echoData)
echo "<strong>$spaces $file</strong><br />";
$subarray = getDirectory( "$path/$file", ($level+1) );
$install_links = array_merge($install_links, $subarray);
// Re-call this same function but on a new directory.
// this is what makes function recursive.
} else {
if (strstr($file,".ipa"))
{
//echo ">>".$file."<<";
$filename = str_replace(".ipa","",$file);
$plist_path = substr($path,2);
$plist_path = str_replace("/","~",$plist_path);
$plist_location = $root_folder_url_prefix.$plist_path."~".$filename.".plist";
$link = '<a href="itms-services://?action=download-manifest&url='.$plist_location.'" onclick="this.color=#FF0000;"> '.$plist_path.'-'.$filename.'</a>';
if ( $echoData)
echo "$spaces $link<br/>";
array_push($install_links,$link);
}
else
{
// echo "$spaces $file<br />";
// Just print out the filename
}
}
}
}
closedir( $dh );
// Close the directory handle
return $install_links;
}
function showPasswordForm()
{
?>
<center>
<form action="index.php" method="post">
<table>
<tr><td>User:</td> <td> <input type="text" name="user" /></td></tr>
<tr><td>Password:</td> <td> <input type="password" name="password" /></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Submit" /></td> </tr>
</table>
</form>
</center>
<?
}
?>
正如您可能已经看到我还没有将js实现到php ....