Friday, September 11, 2009

How to Download files in php

The following code snippet will guide you to implement the php code that will prompt user to download files in his browser window.


<?php
//download.php
//content type
header('Content-type: text/plain');
//open/save dialog box
header('Content-Disposition: attachment; filename="sample.txt"');
//read from server and write to buffer
readfile('test.txt');
?>




<!--List of Content Types
=====================

pdf   --  application/pdf
sig   --  application/pgp-signature
spl   --  application/futuresplash
class  --  application/octet-stream
ps   --  application/postscript
torrent  --  application/x-bittorrent
dvi   --  application/x-dvi
gz   --  application/x-gzip
pac   --  application/x-ns-proxy-autoconfig
swf   --  application/x-shockwave-flash
tar.gz  --  application/x-tgz
tgz   --  application/x-tgz
tar   --  application/x-tar
zip   --  application/zip
mp3   --  audio/mpeg
m3u   --  audio/x-mpegurl
wma   --  audio/x-ms-wma
wax   --  audio/x-ms-wax
ogg   --  audio/x-wav
wav   --  audio/x-wav
gif   --  image/gif
jpg   --  image/jpeg
jpeg   --  image/jpeg
png   --  image/png
xbm   --  image/x-xbitmap
xpm   --  image/x-xpixmap
xwd   --  image/x-xwindowdump
css   --  text/css
html   --  text/html
htm   --  text/html
js   --  text/javascript
asc   --  text/plain
c  -- text/plain
conf  -- text/plain
text  -- text/plain
txt   -- text/plain
dtd   --  text/xml
xml   --  text/xml
mpeg  -- video/mpeg
mpg  -- video/mpeg
mov   --  video/quicktime
qt  -- video/quicktime
avi   --  video/x-msvideo
asf   --  video/x-ms-asf
asx   --  video/x-ms-asf
wmv   --  video/x-ms-wmv
wmp  -- video/x-ms-wmp
wvx  -- video/x-ms-wvx
wm  -- video/x-ms-wm  
mp4    -- video/mp4
mpv2,mp2ve   -- video/x-mpeg2  
rv  -- video/vnd.rn-realvideo
fli,flc       -- video/fli      
3gpp,3gp -- video/3gpp
bz2   --  application/x-bzip
tbz   --  application/x-bzip-compressed-tar
tar.bz2 -- application/x-bzip-compressed-tar -->

0 comments:

Post a Comment

 

About Me

My photo
Hey guys this is Vaseem Ansari, 25 years old, Software & Web Developer, Blogger & works on Open Sources Technologies I love my family and my loved once very much. It takes a while for me to build trust in someone new. I am honest, thoughtful, and my friends tell me that I am wise. I would also say that I am stubborn. but I do learn from my mistakes. I'm Glad I'm Me No one looks The way I do. I have noticed That it's true. No one walks the way I walk. No one talks the way I talk. I am me. There's no one else I'd rather be! Have fun reading this blog and don't forget to subscribe to the feed to keep updated on the latest articles. Visit my Blog at http://www.VaseemAnsari.com/blog/

Followers