php文件下载显示找不到文件怎么办

发布时间:2024-05-07 点击:86
php文件下载显示找不到文件的解决办法:首先打开相应的下载代码文件;然后从浏览器中获取字符的编码;接着使用“mb_convert_encoding”函数转换编码;最后使用“file_exists”函数实现文件下载即可。
推荐:《php视频教程》
php 文件下载 以及 file_exists找不到文件的解决方案
链接:<a href="upload/file/download.php?filename=雨人工作室.doc" target="_blank" >点击下载</a>
其中php:
<?php$filename = $_get['filename'];//从浏览器获取到的字符的编码是utf-8,我们要用这个函数转换成gbk才能才本地找到这个文件$filename = mb_convert_encoding($filename,'gbk','utf-8');echo $filename ."<br>";if( empty($filename)){ echo'<script> alert("非法连接 !"); location.replace ("index.php") </script>'; exit();}if (!file_exists($filename)) { //检查文件是否存在 echo "文件找不到"; exit;} else { $file = fopen($filename,"r"); // 打开文件 // 输入文件标签 header("content-type: application/octet-stream"); header("accept-ranges: bytes"); header("accept-length: ".filesize($filename)); header("content-disposition: attachment; filename=" . $filename); // 输出文件内容 echo fread($file,filesize($filename)); fclose($file); exit();}?>总结:如果没有对浏览器传进来的文件地址进行转码(从utf-8转成gbk),那么file_exists函数将找不到中文名字的文件。

网站网站制作网站的流程是哪些? 需要的费用是多少?
公司注册 域名是怎样的 公司可以有多少个域名
教你对SEO站内优化进行合理的安排!
app怎么测试ipv6
CVE-2019-0193 apache 漏洞利用与安全防护方案
大连网站网站建设方法以及如何推广
郑州网站建设设计是什么?网站建设有何特点?
小程序出现问题了-云建站/云站群/小程序