Page 1 of 1

Display file if possible, otherwise download

Posted: Wed Dec 29, 2010 9:39 am
by shiznatix
I am currently making a media holder website. On this site, there will be lots of types of files, such as .swf, images, etc. I have the files being uploaded to a directory that is not in the server root so that people can not directly access the files, you have to download them from the site.

I also want to have a preview option though. I would like to be able to display a flash banner without using the html markup, just so people can see what it is.

Problem though is that the files are not in the web root. Here is the folder structure:
files/
public_html/

So, how can I read a .swf file (or .jpg) to the browser without it accessing it directly?

Re: Display file if possible, otherwise download

Posted: Thu Dec 30, 2010 3:59 am
by Darhazer
readfile
Before that you have to output the correct Content-type and Content-Length headers. The second one is easy - use the filesize() function

Re: Display file if possible, otherwise download

Posted: Thu Dec 30, 2010 6:50 am
by shiznatix
Thanks, that seams to have done the trick!

Re: Display file if possible, otherwise download

Posted: Thu Dec 30, 2010 9:41 am
by shiznatix
On second thought, is there a list of all file extensions and their ctype? I have a bunch of different file types and I want to be able to set the correct header every time