nginx的编译配置请参考http://wiki.nginx.org/NginxHttpAccessKeyModule
下面分享下关于我的配置:
nginx:
location /downloads { # autoindex on; # autoindex_localtime on; # autoindex_exact_size off; accesskey on; accesskey_hashmethod md5; accesskey_arg "key"; accesskey_signature "mypass$remote_addr"; }
php源码:
$downfile=$_GET["downfile"]; $dir0='/web/html/downloads'; $dir1=str_replace('..','',$_GET['dir1']); $dir=$dir0.$dir1; if ($downfile) { $filename =basename($downfile); $file=fopen($dir."/".$filename,"rb"); Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Accept-Length: ".filesize($dir."/".$filenamee)); Header("Content-Disposition: attachment; filename=".$filename); echo fread($file,filesize($dir."/".$filename)); fclose($file); exit; } ?> <title>SZA</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8";> <STYLE type="text/css"> body {font-family: "sans-serif", "serif"; font-size: 12px;} BODY { background-color:#A2B5CD } a:link {color: #BFEFFF; text-decoration: none} a:visited {color: #080808; text-decoration: none} a:hover {color: #FFFFFF; text-decoration: underline} input {font-family: "sans-serif", "serif";font-size: 12px;} td {font-family: "sans-serif", "Verdana"; font-size: 12px;} .title {font-family: "Verdana", "Tahoma";font-size: 20px;font-weight: bold; color=black} </STYLE> </head> <body> <table width="100%" > <tr> <td align="center">神州IT架构文件分享系统</td> </tr> <tr><td align="right">上传请转至ftp,帐号:ftp 密码:ftpkey </td></tr> </table> <hr> <table width="100%" > <?php $ipkey= md5("mypass".$_SERVER['REMOTE_ADDR']); echo '<form action="" method="post">'; echo '<tr>'; echo '<td>例如你现在的一个链接是:"https://www.linux-ch.com/downloads/iso/rhel- server-6.0-i386-dvd.iso<font color="red">?key=d85b4aa593bkdkfia450ce6a55766e6b"</font></td>'; echo '<tr><td>只要将后面的"<font color="red">?key=d85b4aa593bkdkfia450ce6a55766e6b</font>"删除掉,再提 交到下面进行更新>就行了</td></tr>'; echo '<td>'; echo "输入需要更新的链接:"; echo '<input type="text" name="url" style="font-family:Verdana,Arial; font-size: 9pt; width:60%">'; echo '<input type="submit" value="更新" style="font-family:Verdana,Arial; font-size: 9pt;background-color:#A2B5CD ">'; echo '</td>'; echo '</tr>'; echo '<tr>'; $durl=$_POST['url']; if (!isset($durl) or empty($durl)) { echo " <td> </td></tr>n"; } else { echo "<tr><td>新的下载地址是: </td></tr>n"; echo "<tr><td><a href="".($durl)."?key=".$ipkey."">".($durl)."?key=".$ipkey." </a></td></tr>n"; } echo "</tr>n"; echo '</form>'; echo '<tr>'; echo '<td><b>'; echo "文件列表:"; echo '</b></td>'; echo '</tr>'; ?> </table> <table width="100%" > <?php [email protected]($dir); while ([email protected]($dirs)) { $b="$dir/$file"; [email protected]_dir($b); if($a=="1"){ if($file!=".."&&$file!=".") { echo "<tr>n"; echo " <td><a href="?dir1=".rawurlencode($dir1)."/".rawurlencode($file)."">$file</a></td>n"; echo "</tr>n"; } else { echo "n"; } } } @closedir($dirs); [email protected]($dir); while ([email protected]($dirs)) { $b="$dir/$file"; [email protected]_dir($b); if($a=="0"){ // [email protected]("$dir/$file"); $size = exec ('stat -c %s '. escapeshellarg ("$dir/$file")); if($size >= 1073741824) { $size = round($size / 1073741824 * 100) / 100 . " GB"; } elseif($size >= 1048576) { $size = round($size / 1048576 * 100) / 100 . " MB"; } elseif($size >= 1024) { $size = round($size / 1024 * 100) / 100 . " KB"; } else { $size = $size . " B"; } // [email protected]("Y-n-d H:i:s",filemtime("$dir/$file")); [email protected]("Y-n-d H:i:s",exec('date +%s -r'. escapeshellarg ("$dir/$file"))); echo "<tr>n"; echo "<td>$file</td>n"; echo "<td>$lastsave</td>n"; echo "<td>$size</td>n"; echo "<td><a href=" https://www.linux-ch.com/downloads".rawurlencode($dir1)." /".rawurlencode($file)."?key=".$ipkey."">[下载]</a></td> n"; echo "</tr>n"; } } @closedir($dirs); ?> </table> </body> </html>源码原来是使用urlencode这个参数对链接进行转换的,遇到空格就出问题,后改用rawurlencode将问题解决.
php的源码是在网上找回来修改加工的,在此我要感谢3t,有他的帮助我才能改好这些文件,当然也要感谢将源码发布出来前辈,这样我才有机会去修改这些,谢谢.
声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。