隐蔽服务器上的文件名并指定新文件名供下载
以下源码可以隐蔽文件名,并以指定文件名下载服务器上的文件,用md5加密文件名,以加密后的字符串为键值,下载服务器上对应的文件。
前端页面download.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>下载文件页面</title> </head> <body> <h2>这是一个下载页面</h2> <a href="download.php?f=dde783d2e7615d90342dfeb0d34b048f">rar文件</a> <a href="download.php?f=09141dda21fbb5151d5de47feb1ab976">视频文件</a> <a href="download.php?f=646ccaec24a9ab751e1eda17f912486c">图片文件</a> </body> </html>
后端页面download.php
<?php $f=$_GET['f']; $files=array( 'dde783d2e7615d90342dfeb0d34b048f'=>array('myrar.rar','压缩文件.rar'), '09141dda21fbb5151d5de47feb1ab976'=>array('myvideo.mp4','视频文件.mp4'), '646ccaec24a9ab751e1eda17f912486c'=>array('mypic.jpg','图片文件.png') ); // header("Content-type: text/html; charset=utf-8"); header("Content-Disposition:attachment;filename=".$files[$f][1]); header("Content-Type: application/octet-stream"); $handle=fopen($files[$f][0],'rb'); while ($str = fread($handle,1024)) { echo $str; } // print_r($files); ?>
以上内容来自php中文网https://www.php.cn/code/50721.html,略有改动。

https://img2022.cnblogs.com/blog/1598764/202208/1598764-20220810211749364-1759619413.png
浙公网安备 33010602011771号