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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Download file from area not under apache tree

Status
Not open for further replies.

Niv3k

Programmer
Jul 11, 2001
350
US
Is it possible to download a file from somewhere that is not under the tree?

For example, let's assume that the server's root is:
/usr/local/www

and I have a file: /usr/tmp/myfile.pdf

That I want download from
is it possible to make downloadpdf.php point to and download myfile.pdf?

Kevin
 
Okay, I managed to answer my own question. The following script works on all browsers except IE 4.01 and 5.5<=SP1.
Code:
<?php

Header (&quot;Content-Type: application/pdf&quot;);
Header (&quot;Content-Disposition: attachment;&quot;);

include (&quot;/usr/local/lib/php/Document.PDF&quot;);

?>
But does anyone know how I can make this read from another computer on the network, probably using named pipes,
eg://diff_comp/usr/local/Document.PDF ?

 
i dunno... you could always do a file read and then echo the data after the headers... i would stick with the include though. good idea!

the IE thing is a bug with pdf headers - the best way to fix it is to try restarting IE! no word on a fix.

good luck! -gerrygerry
Go To
 
Yes:

<?
header (&quot;Content-Type: application/octet-stream&quot;);
$path=&quot;../docspdfs&quot;;
header (&quot;Content-Length: &quot;.filesize(&quot;$path/$filename&quot;));
header (&quot;Content-Disposition: attachment; filename=$filename&quot;);
header (&quot;Pragma: no-cache&quot;);
header (&quot;Expires: 0&quot;);
readfile(&quot;$path/$filename&quot;);

?>

where $path is the path to the file and $filename the file name.
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Yes:

<?
header (&quot;Content-Type: application/octet-stream&quot;);
$path=&quot;../docspdfs&quot;;
header (&quot;Content-Length: &quot;.filesize(&quot;$path/$filename&quot;));
header (&quot;Content-Disposition: attachment; filename=$filename&quot;);
header (&quot;Pragma: no-cache&quot;);
header (&quot;Expires: 0&quot;);
readfile(&quot;$path/$filename&quot;);

?>

where $path is the path to the file and $filename the file name.

This should be your download.php script
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
What does Content-Type: application/octet-stream do? why don't I want to use PDF? It seems when I use octet-stream it displays the pdf in my browser window, as if I loaded the pdf in notepad or something...

also - When I add Pragma: no-cache, it can't download the file (at least on IE 5.5 SP 2). Any idea why, Anikin?

But thanks, both for your inputs!

Kevin
 
???

i do that to force all my downloads.

When i put application/octet-stream is to say that is a stream of data, and not only PDF's. This way you can use the same file to upload PDF's, DOC's and even images Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Well, if I did that, then a user would be able to go to that directory and try a bot that tried to download:
a.pdf
b.pdf
c.pdf
...
aa.pdf
ab.pdf

etc...

and I don't want them to be able to do that. The likelihood of them doing that is very small. But the possibility would exist...

Kevin
 
In a simpler scenario, your suggestion makes sense. But here is a simple example of what I'm doing:

User Bob is allowed to download forms A, B, and C
User Sue is allowed to download forms D, E, and F
User Jim is allowed to download forms B and F

Jim doesn't have permission to look at form A for whatever reason. So I don't want Jim to type and download that form... He needs to login and only through the database bringing him the link to B and F can he download them.

Then from the download.php page, I can check the user and session, and if someone tries to download a file, I can deny them access or allow the download...

If he logged in, and A.pdf was in an aliased directory, once he logged in he could easily try to download A.pdf by typing it into the URL. The liklihood of someone trying to view forms they don't have access to is very unlikely. But it is possible, so I am trying to avoid that from the start...

Does that make it a little more clear? I know it's an unusual design and solution, but of all the ones we've looked at, it seems to be the best.

Kevin
 
Ahhh.. That makes more sense now..

Another way, maybe more work is to have a direcory for each user so that they only have access to the files that you specify. But, I suppose it depends how many users you are talking about.. This way, you could specify the files as a link and pass the user + password to a htaccess file to authenticate the user..

I am not saying that you should do this, just thinking out loud..

Hope this helps Wullie

 
Thought about that, but administration of 10k+ users would SUCH a pain. Thanks for the thoughts, tough...

Kevin
 
Thanks, gerrygerry, but it does not appear that is what I'm looking for, since we already have the .pdf's built. But in a few weeks, when we add individual user account ($$$) info, that looks like an idea...

and wullie: yes I originally posted the question in the Apache forum, then quickly realized this was better left to the php forum.

my own disclaimer: I have a boatload of experience with ASP and IIS, but I now work for a small company with a small budget, do PHP and Apache are a better choice based only on $$$ for us. So I hope you all forgive me when I ask any questions like: &quot;In ASP you would do this...&quot; [tongue]

Kevin

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top