auto open behavior for files accessed via php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
D3thk10K
Forum Newbie
Posts: 1
Joined: Fri Sep 24, 2010 1:59 pm

auto open behavior for files accessed via php

Post by D3thk10K »

Hello,

I have a particular situation where files (.doc, xls, .pdf, etc...) are stored outside of the root web and accessed via a php file. It seems I cannot emulate the typical behavior of "auto opening" the file in the appropriate application with this approach. The browser always prompts to save. Is it possible to open the file with php headers or something similarly to directly linking to it?

My primary concern with this situation is that the sites search tool can no longer index these documents.

Thanks in advance.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: auto open behavior for files accessed via php

Post by McInfo »

The way a browser handles different types of files is dependent on how a user has configured the browser. You cannot, as a developer, force the user to open a particular file type with a particular application (which may or may not exist on the client's system). Likewise, you cannot specify the folder to which the user will download the file.

You may have to specify the appropriate Content-Type header when serving the file from PHP so the browser will recognize it.
Post Reply