PHP Classes

Download file: download any file from a server

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 63%Total: 15,088 All time: 59 This week: 60Down
Version License Categories
downloadfileclass 1.0.0GNU General Publi...HTTP, Files and Folders
Description 

Author

Class has simple interface to download any file from a server without displaying the location of the file

Picture of Slava Ivanov
Name: Slava Ivanov <contact>
Classes: 4 packages by
Country: Canada Canada
Age: 56
All time rank: 583 in Canada Canada
Week rank: 180 Down7 in Canada Canada Down

Details

This is very simple and convenient class for any site that has download option. Usually, if you need download option you make a link to the file. By pressing on this link, the user automatically gets the dialog box to download/open file in the link. Example: <a href="/download_folder/download_file.ext">Download Now</a> In this case everything will work fine, but you have to put "download_file.ext" under the web server file system and link will show part of this file system, such as "/download_folder/". In some cases you need to "hide" the file system location of the file, or make available to download from a file system that is not under the web server. Very good examples as publishing spreadsheets, mp3s, files accessible just for particular group of users. DOWNLOADFILE class will cover all of these cases and your link to the download file will look like: <a href="file.phtml">Download Now</a>. Yes this is link to PHP script, not to your file. HOW TO: 1. Copy class DOWNLOADFILE to your includes directory. 2. Create PHP script that will include this class: include("downloadfileclass.inc"); 3. Make instance of the DOWNLOADFILE object: $downloadfile = new DOWNLOADFILE("/dir1/dir2/dir3/filename.ext"); Note: In the constructor of class you MUST specify at least path to the download file. This path is mandatory argument of constructor and it MUST be on same computer where your web server is. It must be accessible from the server - no remote files. You may get this path from Database, pass it as a part of any POST, get it from Session, GET or hardcode it, etc. 4. Use method df_download() to begin download this file: $downloadfile->df_download() Note: This method return FALSE if initialization is not successful and headers with file on success. So, you may check return value. OPTIONS AND FEATURES: 1. In constructor of the class you have additional parameters with default values. DOWNLOADFILE($df_path, $df_contenttype, $df_contentdisposition, $df_filename) $df_path - mandatory parameter, path to download file. $df_contenttype - optional parameter, content type of the file. Default is "application/octet-stream". Example for PDF document "application/pdf". $df_contentdisposition - optional parameter, content disposition. Default is "attachment", you may use "inline" mode too. $df_filename - optional parameter, file name for user. Default is same file name as on your file system, you may specify any. 2. You may change any of parameters at any time, without create additional instances of object: Ex. $downloadfile->df_contenttype = "application/pdf"; 3. Three private methods of the class available, you may use it to get some debug information: df_exists() - return TRUE if file exists by path specified, otherwise FALSE. df_size() - return size of download file. df_permitother() - return part of octal number for group "OTHER". For success download file have to have reading permission for this group. (Numbers 4,5,6,7) 4. One public method available for this class: df_download() - download file, return FALSE for failure and send headers and the file on success. NOTES: 1. If you use session to deliver information about real file path or just start session in file.phtml (file that actually call method of the class) DON'T FORGET before you start session set session_cache_limiter(), ex: session_cache_limiter(""); session_name("SID"); session_start(); 2. DON'T USE in file.phtml (file that actually call method of the class) headers that set expiration date of the file to past, ex: Header("Expires: Sat, Jan 01 2000 01:01:01 GMT"); - DON'T USE IT Author: Viatcheslav Ivanov, E-Witness Inc., Canada; mail: ivanov@e-witness.ca; web: www.e-witness.ca; www.coolwater.ca; www.strongpost.net; version: 1.00 /08.19.2002

  Files folder image Files (3)  
File Role Description
Plain text file downloadfileclass.inc Class Class itself
Accessible without login Plain text file file.phtml Example example of use
Accessible without login Plain text file readme.txt Doc. documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Reuses Unique User Downloads Download Rankings  
 0%1
Total:15,088
This week:0
All time:59
This week:60Down
 User Ratings  
 
 All time
Utility:82%StarStarStarStarStar
Consistency:79%StarStarStarStar
Documentation:74%StarStarStarStar
Examples:71%StarStarStarStar
Tests:-
Videos:-
Overall:63%StarStarStarStar
Rank:810