Home > Backend Development > PHP Tutorial > PHP file download class (supports multiple file types)

PHP file download class (supports multiple file types)

WBOY
Release: 2016-07-25 08:57:14
Original
1506 people have browsed it
Share a php file download class that can support multiple file types, such as php, html, pictures, etc. Friends in need can refer to it.

In the file download classes or methods implemented in PHP, it can be divided into ordinary file downloads and special file downloads (such as PHP files, HTML files, pictures, etc.).

For ordinary file downloads, you only need to write a link pointing to the file, such as: filename.rar.

But for files with relatively high security requirements, a more common approach is to write a function or a class to handle the file download operation and some preparations before downloading.

The PHP file download class shared in this article can support multiple file types. It can download PHP, HTML and other files, and can also pop up a download dialog box when downloading gif, jpg, png and other image files.

Let’s first look at the calling method:

<?php
/**
* 文件下载类
* edit by bbs.it-home.org
*/

//调用方法1:
require_once 'download.class.php';
$down = new download('./path/filename.html','downname.html');
//调用方法2:
require_once 'download.class.php';
$down = new download();
$down->is_attachment = true; //以下载对话框的形式打开
$down->download('../images/imagename.jpg','imagename.jpg');
?>
Copy after login

Attached is the source code for php file download class.



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