大家好!请教一个问题!
1)
我的PHP是APACHE+PHP+MYSQL环境下,在windows系统中.
我的网页用了APACHE的mod_deflate页面进行压缩,但是现在有一个页面,想在线输出TXT文件,供人下载,不知一输出TXT,点保存,TXT文件中的内容是乱码,不知有什么办法解决?
输出TXT下载的代码如下:header("Content-type: application/x-gzip");
header("Content-disposition: attachment; filename=".date("Ymd").".txt");如果不加header("Content-type: application/x-gzip");此句,根本就没法生成。2)我在APACHE的httpd.conf设置了虚拟机如下:
<VirtualHost www.a.com>
ServerName www.a.com
ServerAlias a.com
DocumentRoot D:/soft/a/
<Directory "D:/soft/a">
Options -Indexes
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost www.b.com>
ServerName www.b.com
ServerAlias b.com
DocumentRoot D:/soft/b/
<Directory "D:/soft/b">
Options -Indexes
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
不知为什么,输入那个网址,都是浏览同一个文件夹中的内容?
谢谢!!
1)
我的PHP是APACHE+PHP+MYSQL环境下,在windows系统中.
我的网页用了APACHE的mod_deflate页面进行压缩,但是现在有一个页面,想在线输出TXT文件,供人下载,不知一输出TXT,点保存,TXT文件中的内容是乱码,不知有什么办法解决?
输出TXT下载的代码如下:header("Content-type: application/x-gzip");
header("Content-disposition: attachment; filename=".date("Ymd").".txt");如果不加header("Content-type: application/x-gzip");此句,根本就没法生成。2)我在APACHE的httpd.conf设置了虚拟机如下:
<VirtualHost www.a.com>
ServerName www.a.com
ServerAlias a.com
DocumentRoot D:/soft/a/
<Directory "D:/soft/a">
Options -Indexes
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost www.b.com>
ServerName www.b.com
ServerAlias b.com
DocumentRoot D:/soft/b/
<Directory "D:/soft/b">
Options -Indexes
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
不知为什么,输入那个网址,都是浏览同一个文件夹中的内容?
谢谢!!
压缩和输出下载文件是两码事。APACHE的mod_deflate 只是传输压缩。
仿一下面的的试试 Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($sourcePath));
Header("Content-Disposition: attachment; filename=" . $file_name);
echo fread($sourcePath,filesize($sourcePath));
header("Content-type: application/x-gzip");
header("Content-disposition: attachment; filename=s_h-".date("Ymd").".txt");