PHP 文件上传功能实现代码

yipeiwu_com6年前PHP代码库
个人认为PHP文件的上传和下载的思路差不多一样.也就是在代码中多了一个header语句
以下是详细的代码.仅供参考.
入口文件
复制代码 代码如下:

<html>
<body>
<form action="download.php" method="GET"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="FileName" id="Fileid" value="<?php echo $_FILES["file"]["name"];?>" />
<h1></h1>
<input type="submit" name="submit" value="download" />
</form>
</body>
</html>
php写的处理文件
<?php
if( empty($_GET['FileName'])){
echo'<script> alert("非法连接 !"); location.replace ("./fileload.html") </script>'; exit();
}
$file_name=$_GET['FileName'];//得到要下载的文件
if (!file_exists($file_name)) { //检查文件是否存在
echo "文件找不到";
exit;
} else {
$file = fopen( $file_name,"r"); // 打开文件
// 输入文件标签
Header("Content-type: application/octet-stream");
//Header("Accept-Ranges: bytes");
//Header("Accept-Length: ".filesize( $file_name));
//Header("Content-Disposition: attachment; filename=" . $file_name);
// 输出文件内容
echo fread($file,filesize( $file_name));
fclose($file);
exit();
}
?>

以上代码是自己在网上找的,可是都不很齐全.记过了一段时间的调试与修改.终于把功能实现了.由于太兴奋了第一时间拿来和大家分享了.

相关文章

一些使用频率比较高的php函数

1.产生随机字符串函数 function random($length) { $hash = @#@#; $chars = @#abcdefghijklmnopqrstuvwxyz012...

php常用Output和ptions/Info函数集介绍

flush函数:刷新输出缓冲ob_clean函数:清空输出缓冲ob_end_clean函数:清空缓冲区并且关闭正在进行的输出缓冲ob_end_flush函数:发送缓冲区数据并且关闭缓冲区...

PHP类的声明与实例化及构造方法与析构方法详解

本文实例讲述了PHP类的声明与实例化及构造方法与析构方法。分享给大家供大家参考,具体如下: <?php class human{ public static $le...

PHP载入图像imagecreatefrom_gif_jpeg_png系列函数用法分析

本文实例分析了PHP载入图像imagecreatefrom_gif_jpeg_png系列函数用法。分享给大家供大家参考,具体如下: imagecreatefrom 系列函数用于从文件或...

PHP7如何开启Opcode打造强悍性能详解

PHP7如何开启Opcode打造强悍性能详解

前言 鸟哥在博客中说,提高PHP 7性能的几个tips,第一条就是开启opcache: 记得启用Zend Opcache, 因为PHP7即使不启用Opcache速度也比PHP-5.6启用...