Home > Backend Development > PHP Tutorial > PHP用代码实现文件上载

PHP用代码实现文件上载

WBOY
Release: 2016-06-13 13:20:37
Original
900 people have browsed it

PHP用代码实现文件下载

?

<?
 if( empty($_GET['FileName'])|| empty($_GET['FileDir'])|| empty($_GET['FileId'])){
     echo'<script> alert("非法连接 !"); location.replace ("index.php") </script>'; exit();
 }
 $file_name=$_GET['FileName'];
 $file_dir=$_GET['FileDir'];
 $FileId=$_GET['FileId'];
 $file_dir = $file_dir."/";
 if   (!file_exists($file_dir.$file_name))   {   //检查文件是否存在  
   echo   "文件找不到";  
   exit;    
   }   else   {  
 $file = fopen($file_dir . $file_name,"r"); // 打开文件
 // 输入文件标签
 Header("Content-type: application/octet-stream");
 Header("Accept-Ranges: bytes");
 Header("Accept-Length: ".filesize($file_dir . $file_name));
 Header("Content-Disposition: attachment; filename=" . $file_name);
 // 输出文件内容
 echo fread($file,filesize($file_dir . $file_name));
 fclose($file);
 exit();
 }
 ?>
Copy after login

?

网友回复:

if (!file_exists($file_dir.$file_name)) { //检查文件是否存在?
这个是错误的,检查文件是否存在要用is_file,file_exists在文件不存在但是文件夹存在的时候也会返回TRUE。

?

From:http://www.cnblogs.com/analyzer/articles/1393967.html

?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template