Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a File for View!!

Status
Not open for further replies.

Bernini

Programmer
Oct 26, 2004
98
0
0
MT
Hi All

I have a folder that contains various files (pdfs, .doc, .xls, .txt) . Now i have a list of files on my page and i would like that when the file is clicked it will open within the browser (those that have plugins such as pdf or word docs)!

I'm using the following code to open it:

Code:
 header('Content-Length: '.filesize($filename));
 header('Cache-control: private');
 header('Content-Type: ' . $mimetype);
 header('Content-Disposition: inline; filename=' . $realname . '');
 header('Last-Modified: '. date('D, j M Y G:i:s T',$modified));
readfile($filename);

Where the $filename represents the direct path to the actual file, $mimetype is the mimetype of the file, $realname is the name of the file.

Now what is happening is this, when i click the file a window for downloading an activex object and the filename is the url! i cannot figure out what is wrong!

Any help will be most appreciated!

Regards
B
 
Question:

Are these files in web space? If so, why not just print out the HTML for an old fashioned always working hyperlink?
The web server will make sure all the encoding is done correctly and you don't have to create the overhead of writing the transfer code.
 
Yeah, if you have the right plugins then all you have to do is link to the file and it'll open in the browser (pdfs straight away, docs will ask the user).
 
You're both right and i agree with you! the thing is this since this web site is the company's intranet the documents are quite important and when one links directly to the file then the link will be available in the history and if some unauthorized or under privelegded user finds the link than he can acces the file since it will be cached!

i would like to have uncached files witout history! if possible!! any ideas would be immensly appreciated!

Thanks once again for your input!
B
 
Either way the files will end up in some temporary file on the machine. The only way to get rid of the temporary files is to empty the Internet Cache upon exit.

The file is not publicly accessible, right? There is some kind of access control I suppose.
Then the question is:
Who in the first place looks at a file and from where? From a public computer or from their workstation?

PHP has no deterministic influence on client side caching. Browsers behave very differently. The only (and for IE I wonder) failsafe solution is the local cache purge.
 
hmmm...so you're sayng that the user should empty the cache once he closes the browser!! seems quite un feaseable!

to answer your first question ... each user should have his or her own workstation to access the files but it can occur that a laptop is used etc of some one else...so the files remain there!

Well, if you hve any idea of how the cahce can be emptied pls forward the info!

Once again i thank you!
B
 
Solution:
Company Policy.
Since the files are access protected it can be easily tracked who accessed what from where.
Most workstations require users to log onto the network. A general policy like that makes users reponsible for content they view. A no-share password policy...
WHen a user leaves a workstation, laptop etc. they log off. User profiles and temporary files can only be accessed by administrators and the user themselves.

You will have this problem only when there is shared use of company resources under one anonymous account. I would strongly recommend to change that.

Since the Web is such a great thing to share things users must develop an attitude to keep proprietary things from the public.
 
I totally agree with you and the policy that u sat out, though its rarley the case unfortunetly! But i will try to your suggsted solution!

Thanks
B

ps. if you get any other idea pls inform me hehe!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top