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

Download Link 2

Status
Not open for further replies.

BlindPete

Programmer
Jul 5, 2000
711
US
How do i create a link for a file to be downloaded when that file is not located in the public area?

For Example on the server:
file <- files to be downloaded
Public Html\MyDownload.php <- file containing links

Sorry if this is not too clear. I do not want the files for download accessable accept from the MyDownload.php page which is password protected and session controled page.

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
<a href='myfiletobedownloaded'>Click here to DL</a>

Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
specify a relative url, such as:

<a href='../file.ext'>Click here to DL</a>

the ../ tells the server to look one level up from the current directory
 
thanks fellas but both of those only work if the file to be downloaded is it self within the public area. How can I do it when the file is not in the public area?

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
blind, the file needs to be in a 'public' directory.. if you're trying to stop un-authorized persons from grabbing the file, providing links to the file won't help *unless you're requiring a login to authenticate permission to download.

If that's the case you can put the file in a .htaccess protected directory and grab the file from there..
 
You could have PHP feed the file to your users. Just put something like:
Code:
<?php
header('Content-Type: application/octet-stream');
readfile('../files/' . $_GET['file']);
?>
Of course, you'd need a lot more error checking and you need to strictly parse the file argument, or bad things can/will happen.

//Daniel
 
ypu, daniel's is the best method, the user will not know ur file path that way...

Known is handfull, Unknown is worldfull
 
Why don't set &quot;Alias /source/&quot; on apache and restric the directory only to get the named file? so:

<a href='/source/file.to.get'>Get the file</a>

but if you try you got a &quot;Access Forbidden&quot;
 
Hi folks.... while not a total success you'all got me in the correct direction. many thanks ;-)

Code:
<?php
$filename=&quot;&quot;; // the name the file will have on client computer
$file_to_download=&quot;&quot;; // the name the file has on the server (or an FTP or HTTP request)
$user_agent = strtolower ($_SERVER[&quot;HTTP_USER_AGENT&quot;]);
header( &quot;Content-type: application/force-download&quot; );
if ((is_integer (strpos($user_agent, &quot;msie&quot;))) && (is_integer (strpos($user_agent, &quot;win&quot;)))) {
  header( &quot;Content-Disposition: filename=&quot;.$filename);
} else {
  header( &quot;Content-Disposition: attachment; filename=&quot;$filename);
}
header( &quot;Content-Description: File Transfert&quot;);
@readfile($file_to_download);
?>


-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
I have a question regarding this technique.

Most people use a javascript:window.open to call the download.php file.
After the file we want to force downloading is indeed downloaded, I could not use javascript:window.close() to close the window were download.php is.

Any ideas?

Thx

Ricardo Vercesi
Development Manager
IT On Time
a DOTONESGPS company
 
are you using the close window in an onclick event? or the line following
@readfile($file_to_download);

or just post your code :)

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top