【求大神】访问任意文件url返回任意文件名给用户下载??????
访问任意文件url返回任意文件名给用户下载??????
案例:
http://down1.020pidai.com/8935/服务器里面其实只有一个文件..
如000000.exe
要现实的功能是:
用户访问任意名称就可以下载任意名称的文件 , 而不会出现404错位文件不存在的情况
访问
http://down1.020pidai.com/8935/111111.exe
服务器返回111111.exe给用户下载,用户下载看到的文件名为111111.exe而不是服务器上的000000.exe
http://down1.020pidai.com/8935/222222.exe
服务器返回222222.exe给用户下载,,用户下载看到的文件名为222222.exe而不是服务器上的000000.exe
麻烦大神
回复讨论(解决方案)
就是不管用户输什么名字,都只下载000000.exe这个文件?
header("Content-Disposition: attachment; filename=000000.exe");
就是不管用户输什么名字,都只下载000000.exe这个文件?
header("Content-Disposition: attachment; filename=000000.exe");
你的代码是访问任何url下载000000.exe 但接收的文件名是000000.exe
就是不管用户输什么名字,都只下载000000.exe这个文件?
header("Content-Disposition: attachment; filename=000000.exe");
我要的效果是 服务器只有000000.exe 一个文件
用户访问 www.url.com/down/111111.exe 会保存111111.exe而不是保存000000.exe
用户访问 www.url.com/down/222222.exe 会保存222222.exe而不是保存000000.exe
用 urlrewrite 隐去入口文件名
于是 http://down1.020pidai.com/8935/222222.exe 中的 /8935/222222.exe 就作为 PATH_INFO 传入入口文件
而 /8935/222222.exe 中的
8935 就可代表实际的 000000.exe
222222.exe 就是 header("Content-Disposition: attachment; filename=$filename"); $filename
能够理解吗?
用 urlrewrite 隐去入口文件名
于是 http://down1.020pidai.com/8935/222222.exe 中的 /8935/222222.exe 就作为 PATH_INFO 传入入口文件
而 /8935/222222.exe 中的
8935 就可代表实际的 000000.exe
222222.exe 就是 header("Content-Disposition: attachment; filename=$filename"); $filename
能够理解吗?
代码这样写???貌似代码没提及到去下载000000.exe
header("Content-Disposition: attachment; filename=$filename"); $filename
?>
还有怎么访问这个呢? 以上代码保存为exe.php放在根目录www.url.com/exe.php
www.url.com/down/***
伪静态重写www.url.com/exe.php ???
是否这样??
已明白!!
全部代码
新建exe.php
代码:
header("Content-Disposition: attachment; filename=$filename"); $filename
?>
新建.htaccess文件
代码:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ ? [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
新建目录8935
目录8935下新建.htaccess文件
代码如下:
RewriteEngine On
RewriteBase /8935/
RewriteRule ^000000\.exe$ ? [L]
RewriteRule . /000000.exe [L]
在目录8935下放000000.exe即可
这样就达到访问www.url.com/8935/随意写名字.exe
得到的文件为:
随意写名字.exe
apache可以了iis的httpd.ini 怎么弄呢,可以实现不
用 urlrewrite 隐去入口文件名
于是 http://down1.020pidai.com/8935/222222.exe 中的 /8935/222222.exe 就作为 PATH_INFO 传入入口文件
而 /8935/222222.exe 中的
8935 就可代表实际的 000000.exe
222222.exe 就是 header("Content-Disposition: attachment; filename=$filename"); $filename
能够理解吗?
版主iis可以实现这样的效果吗,httpd.ini里面

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...
