时间:2021-07-01 10:21:17 帮助过:9人阅读
用header头下载
用header头下载 能不能给个测试程序啊
已??你?好了
- <!--?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){
- if(!is_dir($root.$file)){
- echo "".$root.$file."<br/-->";
- } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') {
- $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
- $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
- OB_start();
- function DownLoad($info,$file) {
- OB_Clean();
- if(!file_exists($info)) {
- exit('Error:'.__LINE__.','.basename(__FILE__).'!');
- }
- $info=file_get_contents($info);
- header('Content-Transfer-Encoding: binary');
- header('Content-Type: application/force-download; name="'.$file.'"');
- header('Content-Disposition: attachment; filename='.$file.'');
- header('Cache-control: private');
- header('Pragma: no-cache');
- header('Expires: 0');
- echo $info;
- die();
- }
- DownLoad($path.$file,$file);}
已??你?好了
不行啊 直接把php文件下下来了
- <!--?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){
- if(!is_dir($root.$file)){
- echo "".$root.$file."<br/-->";
- } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') {
- $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
- $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
- OB_start();
- function DownLoad($info,$file) {
- OB_Clean();
- if(!file_exists($info)) {
- exit('Error:'.__LINE__.','.basename(__FILE__).'!');
- }
- $info=file_get_contents($info);
- header('Content-Transfer-Encoding: binary');
- header('Content-Type: application/force-download; name="'.$file.'"');
- header('Content-Disposition: attachment; filename='.$file.'');
- header('Cache-control: private');
- header('Pragma: no-cache');
- header('Expires: 0');
- echo $info;
- die();
- }
- DownLoad($path.$file,$file);}
已??你?好了
- <!--?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){
- if(!is_dir($root.$file)){
- echo "".$root.$file."<br/-->";
- } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') {
- $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
- $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
- OB_start();
- function DownLoad($info,$file) {
- OB_Clean();
- if(!file_exists($info)) {
- exit('Error:'.__LINE__.','.basename(__FILE__).'!');
- }
- $info=file_get_contents($info);
- header('Content-Transfer-Encoding: binary');
- header('Content-Type: application/force-download; name="'.$file.'"');
- header('Content-Disposition: attachment; filename='.$file.'');
- header('Cache-control: private');
- header('Pragma: no-cache');
- header('Expires: 0');
- echo $info;
- die();
- }
- DownLoad($path.$file,$file);}
file_put_contents('download/excel.csv',$str);
header("location:download/excel.csv"); //让电脑自动弹出下载对话框
file_put_contents('download/excel.csv',$str);
header("location:download/excel.csv"); //让电脑自动弹出下载对话框 加在哪里啊 怎样加
已??你?好了
- <!--?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){
- if(!is_dir($root.$file)){
- echo "".$root.$file."<br/-->";
- } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') {
- $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
- $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
- OB_start();
- function DownLoad($info,$file) {
- OB_Clean();
- if(!file_exists($info)) {
- exit('Error:'.__LINE__.','.basename(__FILE__).'!');
- }
- $info=file_get_contents($info);
- header('Content-Transfer-Encoding: binary');
- header('Content-Type: application/force-download; name="'.$file.'"');
- header('Content-Disposition: attachment; filename='.$file.'');
- header('Cache-control: private');
- header('Pragma: no-cache');
- header('Expires: 0');
- echo $info;
- die();
- }
- DownLoad($path.$file,$file);}
已??你?好了
- <!--?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){
- if(!is_dir($root.$file)){
- echo "".$root.$file."<br/-->";
- } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') {
- $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
- $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
- OB_start();
- function DownLoad($info,$file) {
- OB_Clean();
- if(!file_exists($info)) {
- exit('Error:'.__LINE__.','.basename(__FILE__).'!');
- }
- $info=file_get_contents($info);
- header('Content-Transfer-Encoding: binary');
- header('Content-Type: application/force-download; name="'.$file.'"');
- header('Content-Disposition: attachment; filename='.$file.'');
- header('Cache-control: private');
- header('Pragma: no-cache');
- header('Expires: 0');
- echo $info;
- die();
- }
- DownLoad($path.$file,$file);}
href='?do 改成 href='a.php?do
a.php就是你自己的那?php文件的文件名
已??你?好了
- <!--?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){
- if(!is_dir($root.$file)){
- echo "".$root.$file."<br/-->";
- } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') {
- $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
- $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
- OB_start();
- function DownLoad($info,$file) {
- OB_Clean();
- if(!file_exists($info)) {
- exit('Error:'.__LINE__.','.basename(__FILE__).'!');
- }
- $info=file_get_contents($info);
- header('Content-Transfer-Encoding: binary');
- header('Content-Type: application/force-download; name="'.$file.'"');
- header('Content-Disposition: attachment; filename='.$file.'');
- header('Cache-control: private');
- header('Pragma: no-cache');
- header('Expires: 0');
- echo $info;
- die();
- }
- DownLoad($path.$file,$file);}
已??你?好了
不行啊 直接把php文件下下来了
- <!--?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){
- if(!is_dir($root.$file)){
- echo "".$root.$file."<br/-->";
- } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') {
- $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
- $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
- OB_start();
- function DownLoad($info,$file) {
- OB_Clean();
- if(!file_exists($info)) {
- exit('Error:'.__LINE__.','.basename(__FILE__).'!');
- }
- $info=file_get_contents($info);
- header('Content-Transfer-Encoding: binary');
- header('Content-Type: application/force-download; name="'.$file.'"');
- header('Content-Disposition: attachment; filename='.$file.'');
- header('Cache-control: private');
- header('Pragma: no-cache');
- header('Expires: 0');
- echo $info;
- die();
- }
- DownLoad($path.$file,$file);}
我的文件名叫 download.php 改了也还是不行 你帮我看看吧
$root="D:/wamp/www/panjinli/downloadsouce";
if(is_dir($root))
{
$openHandle=opendir($root);
while(false!==($file=readdir($openHandle)))
{
if(!is_dir($root.$file))
{
echo "".$root.$file."
";
}
}
closedir($openHandle);
}else
{
echo "文件夹不存在";
}
$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';
if($do=='down')
{
$file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
$path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
OB_start();
function DownLoad($info,$file)
{
OB_Clean();
if(!file_exists($info))
{
exit('Error:'.__LINE__.','.basename(__FILE__).'!');
}
$info=file_get_contents($info);
header('Content-Transfer-Encoding: binary');
header('Content-Type: application/force-download; name="'.$file.'"');
header('Content-Disposition: attachment; filename='.$file.'');
header('Cache-control: private');
header('Pragma: no-cache');
header('Expires: 0');
echo $info;
die();
}
DownLoad($path.$file,$file);
}
?>
已??你?好了
不行啊 直接把php文件下下来了
- <!--?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){
- if(!is_dir($root.$file)){
- echo "".$root.$file."<br/-->";
- } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') {
- $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
- $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
- OB_start();
- function DownLoad($info,$file) {
- OB_Clean();
- if(!file_exists($info)) {
- exit('Error:'.__LINE__.','.basename(__FILE__).'!');
- }
- $info=file_get_contents($info);
- header('Content-Transfer-Encoding: binary');
- header('Content-Type: application/force-download; name="'.$file.'"');
- header('Content-Disposition: attachment; filename='.$file.'');
- header('Cache-control: private');
- header('Pragma: no-cache');
- header('Expires: 0');
- echo $info;
- die();
- }
- DownLoad($path.$file,$file);}
已??你?好了
不行啊 直接把php文件下下来了
- <!--?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){
- if(!is_dir($root.$file)){
- echo "".$root.$file."<br/-->";
- } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') {
- $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
- $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
- OB_start();
- function DownLoad($info,$file) {
- OB_Clean();
- if(!file_exists($info)) {
- exit('Error:'.__LINE__.','.basename(__FILE__).'!');
- }
- $info=file_get_contents($info);
- header('Content-Transfer-Encoding: binary');
- header('Content-Type: application/force-download; name="'.$file.'"');
- header('Content-Disposition: attachment; filename='.$file.'');
- header('Cache-control: private');
- header('Pragma: no-cache');
- header('Expires: 0');
- echo $info;
- die();
- }
- DownLoad($path.$file,$file);}
已??你?好了
不行啊 直接把php文件下下来了
- <!--?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){
- if(!is_dir($root.$file)){
- echo "".$root.$file."<br/-->";
- } } closedir($openHandle);}else{echo "文件夹不存在";}$do=(isset($_REQUEST['do'])) ? addslashes($_REQUEST['do']) : '';if($do=='down') {
- $file=(isset($_REQUEST['file'])) ? addslashes($_REQUEST['file']) : '';
- $path=(isset($_REQUEST['path'])) ? addslashes($_REQUEST['path']) : '';
- OB_start();
- function DownLoad($info,$file) {
- OB_Clean();
- if(!file_exists($info)) {
- exit('Error:'.__LINE__.','.basename(__FILE__).'!');
- }
- $info=file_get_contents($info);
- header('Content-Transfer-Encoding: binary');
- header('Content-Type: application/force-download; name="'.$file.'"');
- header('Content-Disposition: attachment; filename='.$file.'');
- header('Cache-control: private');
- header('Pragma: no-cache');
- header('Expires: 0');
- echo $info;
- die();
- }
- DownLoad($path.$file,$file);}