473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Returning a file to browser via php

Hello all.

I need to be able to "send, or stream" a file to the client browser
using PHP code. This is the scenario.
The user clicks a link on a page (after logging in to the site). I
need to have my PHP code return a document -a Word document file, let's
say - to the browser for display. However, the document is not in the
public WWW folder. For security reasons, it is on another drive on the
same machine.
I need to have the php code return the file to the browser so that I
can wrap security code around this process.

Thanks in advance, any insight is greatly appreciated !

Jul 17 '05 #1
2 1919
<?php
header('Content-Type: application/msword');
header('Content-Disposition: attachment; filename=filename.doc');
readfile('/not/in/web/root/word.doc');
?>

Best regards,

Peter Albertsson

"SLOGIC" <wh*******@biz-spot.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Hello all.

I need to be able to "send, or stream" a file to the client browser
using PHP code. This is the scenario.
The user clicks a link on a page (after logging in to the site). I
need to have my PHP code return a document -a Word document file, let's
say - to the browser for display. However, the document is not in the
public WWW folder. For security reasons, it is on another drive on the
same machine.
I need to have the php code return the file to the browser so that I
can wrap security code around this process.

Thanks in advance, any insight is greatly appreciated !

Jul 17 '05 #2
"SLOGIC" <wh*******@biz-spot.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Hello all.

I need to be able to "send, or stream" a file to the client browser
using PHP code. This is the scenario.
The user clicks a link on a page (after logging in to the site). I
need to have my PHP code return a document -a Word document file, let's
say - to the browser for display. However, the document is not in the
public WWW folder. For security reasons, it is on another drive on the
same machine.
I need to have the php code return the file to the browser so that I
can wrap security code around this process.

Thanks in advance, any insight is greatly appreciated !


You might be making this more complicated than it needs to be.

You already have the physical files stored outside the web server root.
Authenticate the user and give them a link to download the file.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Earl T | last post by:
When I try to get the netscape version for version 7, I get the HttpBrowserCapabilities class returning the version as 5 and not 7. (see code and output below) CODE HttpBrowserCapabilities...
10
by: KeithRaginF | last post by:
Hello I am trying to return the contents of an Excel file. However, I don't want to just redirect the request to the Excel file since it does not reside in a location where that is appropriate. ...
3
by: David Thielen | last post by:
Hello; When I get a request for a page, how can I return a pdf as the page contents? In java the way to do this is for the response set it's type to "application/pdf" and then get a byte (not...
23
by: Peter | last post by:
I have a problem with a page show_image.asp that returns a jpg image under Windows XP Pro SP2. The page sets content type as: Response.ContentType = "image/jpg" While this works perfectly fine...
2
by: maglev_now | last post by:
After the user downloads a file from filedownload.aspx I am unable to get them back to the default page for my site. Any suggestions? code from filedownload.aspx Private Sub Page_Load(ByVal...
5
by: Mohammed Hamama | last post by:
Hi all, I am using a windows 2000 server with IISLockdown and ISAPI_Rewrite installed on it. I have 2 websites A & B. ASP pages on A are working properly, but when placed one B they return 404...
2
by: Steve Harclerode | last post by:
Hi all, I have a web application that uploads a file into a SQL database as a stream of bytes. On another page of the app, I retrieve the same byte stream from SQL, and my ultimate goal is...
1
by: CoreNeter | last post by:
I have an aspx page which contains some HTML and an aspx.cs which contains some C# code. In the aspx.cs file I have a string(of XML data) which I would like to send to the browser. Response.Write...
12
by: Karlo Lozovina | last post by:
I'm not sure if Python can do this, and I can't find it on the web. So, here it goes: try: some_function() except SomeException: some_function2() some_function3() ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.