WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : How to force the user to download a file instead of opening it up in an controlled environment within the browser (i.e. MS Word/Adobe Acrobat)
Categories : Browsers, PHP, HTTP Update Picture
Chris Sano
Date : Jul 10th 2000
Grade : 3 of 5 (graded 4 times)
Viewed : 8856
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Chris Sano
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

I wrote this snippet of code to force the user to download my resume to their hard drives
rather than opening it up in the browser (since this has been known to cause some problems
on different platforms).

Files to be downloaded:
resume.doc, resume.rtf, resume.pdf

Link:
[ <a href="resume.php3?application=application/msword&fileName=resume.doc">.doc</a> ]

Variable explanations:
$application was set as application/msword for the .doc and .rtf files and application/octet-
stream for the .pdf file

$fileName was the file to be downloaded (resume.doc, resume.rtf, or resume.pdf)

And finally, the code:
(nothing other than what is below should be in the php file)
<?
$file = fopen("$fileName","r");
header("Content-type: $application");
header("Content-Disposition: attachment; filename=$fileName");
header("Content-Description: PHP3 Generated Data");
header("Pragma: no-cache");
header("Expires: 0");
fpassthru($file);
fclose($file);
?>



Browser Detection, Redirection Type, MSIE, MOZILLA, Netscape Navigator, NS, $HTTP_USER_AGENT, HTTP_USER_AGENT
Categories : PHP, HTTP, Browsers, HTML and PHP
Simple Password example
Categories : PHP, Authentication, Security, HTTP
WebServerSpy checks which kind of Webserver is running, Apache, Netscape, Fasttrack, IIS, HTTP-Header, HTTP 1.0, GET, spy, WWW
Categories : HTTP, Network, Apache, PHP, Web Servers
This gets the http response headers for a given url and returns them in an assoc array. i.e. to test if a url exists: $array = get_http_headers($url); if($array[result]=200) { }
Categories : HTTP, Arrays, PHP
Gets the browser and OS from the $_SERVER['http_user_agent'] variable in PHP
Categories : PHP, HTTP, Regexps
Remote File Saving with PHP - Download and serve a remote file. The content of the file will be updated at fixed intervals.
Categories : PHP, Filesystem, Cache, Sockets, HTTP
A function to check if a URL exists
Categories : PHP, CURL, HTTP
Simple pipe delimited file export program that downloads to a local machine
Categories : PHP, Filesystem, Databases, MySQL, HTTP
PHP4 HTTP Compression Speeds up the Web
Categories : PHP, Zlib, HTML and PHP, HTTP, Network
Authentication HTTP protocol POST
Categories : Authentication, HTTP, PHP
Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem
Remote File Size
Categories : PHP, Filesystem, HTTP, Sockets
The first step Guest Book ... ^^
Categories : MySQL, PHP, Apache, HTML, HTTP
The simple counter with use MySql and gd.
Categories : MySQL, HTTP, Graphics, PHP, Databases
HTTP Basic Authentication via POP3.
Categories : Authentication, HTTP, Email, PHP
 Max Power wrote :658
that doesnt work in ie5.5, bugs