Home >Backend Development >PHP Tutorial >PHP file download class (supports multiple file types)
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'); ?> Attached is the source code for php file download class. |