首页 / PHP / 这样为什么不能实现文件下载
这样为什么不能实现文件下载
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了这样为什么不能实现文件下载,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含11510字,纯文字阅读大概需要17分钟。
内容图文
![这样为什么不能实现文件下载](/upload/InfoBanner/zyjiaocheng/193/a332352088504e988168872b3ccbc6b4.jpg)
if(is_dir($root))
{
$openHandle=opendir($root);
while(false!==($file=readdir($openHandle)))
{
if(!is_dir($root.$file))
{
echo "".$file."
";
echo "$root$file
";
}
}
closedir($openHandle);
}
else
{
echo "文件夹不存在";
}
?>
这段代码为什么不能实现文件下载 浏览器:搜狗浏览器 IE 都试了
回复讨论(解决方案)
用header头下载
用header头下载 能不能给个测试程序啊
已??你?好了
"; } } 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);}
已??你?好了
"; } } 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文件下下来了
已??你?好了
"; } } 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);}
错误代码:27
file_put_contents('download/excel.csv',$str);
header("location:download/excel.csv"); //让电脑自动弹出下载对话框
file_put_contents('download/excel.csv',$str);
header("location:download/excel.csv"); //让电脑自动弹出下载对话框 加在哪里啊 怎样加
已??你?好了
"; } } 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);}
if($do=='down')这个判断始终没有成功 后面大括号内代码没机会执行 怎么办啊
已??你?好了
"; } } 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);}
你这条语句是不是有问题啊 “echo "".$root.$file."
";” 该怎么改啊
href='?do 改成 href='a.php?do
a.php就是你自己的那?php文件的文件名
已??你?好了
"; } } 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);}
错误代码:27 ??描述是啥?????出??你看一下
已??你?好了
"; } } 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?型.
我的文件名叫 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$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "".$root.$file."不行啊 直接把php文件下下来了
"; } } 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."不行啊 直接把php文件下下来了
"; } } 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?型.
你是在LINUX下测的吗 我放在WINDOWS上不能成功执行 放在LINUX下载的文件会被写入一部分乱七八糟的内容 求支援啊
已??你?好了
<?php$root="D:/ghost/";if(is_dir($root)){ $openHandle=opendir($root); while(false!==($file=readdir($openHandle))){ if(!is_dir($root.$file)){ echo "".$root.$file."不行啊 直接把php文件下下来了
"; } } 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?型.
你是在LINUX下测的吗 我放在WINDOWS上不能成功执行 放在LINUX下载的文件会被写入一部分乱七八糟的内容 求支援啊 我在windows和linux下都???,一切正常
内容总结
以上是互联网集市为您收集整理的这样为什么不能实现文件下载全部内容,希望文章能够帮你解决这样为什么不能实现文件下载所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。