安全|下载
????? 你可能会笑我"下载文件"如此简单都值得说?当然并不是想象那么简单。例如你希望客户要填完一份表格,才可以下载某一文件,你第一个想法一定是用 "Redirect"的方法,先检查表格是否已经填写完毕和完整,然后就将网址指到该文件,这样客户才能下载,但如果你想做一个关于"网上购物"的电子商务网站,考虑安全问题,你不想用户直接复制网址下载该文件,笔者建议你使用PHP直接读取该实际文件然后下载的方法去做。程序如下:
??????????? $file_name = "tianhys.exee";
??????????? $file_dir = "/public/www/download/";
??????????? if (!file_exists($file_dir . $file_name)) { //检查文件是否存在
??????????? echo "文件找不到";
??????????? exit;
??????????? } else {
??????????? $file = fopen($file_dir . $file_name,"r"); // 打开文件
??????????? // 输入文件标签
??????????? Header("Content-type: application/octet-stream");
??????????? Header("Accept-Ranges: bytes");
??????????? Header("Accept-Length: ".filesize($file_dir . $file_name));
??????????? Header("Content-Disposition: attachment; filename=" .$file_name);
??????????? // 输出文件内容
??????????? echo fread($file,filesize($file_dir . $file_name));
??????????? fclose($file);
??????????? exit;}
????? 而如果文件路径是"http" 或者 "ftp" 网址的话,则源代码会有少许改变,程序如下:
?
??????????? $file_name = "tianhys.exe";
??????????? $file_dir = "http://www.tianhys.org/";
??????????? $file = @ fopen($file_dir . $file_name,"r");
??????????? if (!$file) {
??????????? echo "文件找不到";
??????????? } else {
??????????? Header("Content-type: application/octet-stream");
??????????? Header("Content-Disposition: attachment; filename=" .$file_name);
??????????? while (!feof ($file)) {
??????????? echo fread($file,50000);
??????????? }
??????????? fclose ($file);
??????????? }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment