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

header Location problem

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
Hi everybody,

I made a script called "download.php" to download files from a specific directory in my server. The idea is I don't want a direct links to my files. Call to the script will be like the following:

download.php?filename=test.wmv

test.wmv is stored in a directory called /files/

The script is working fine, but I have a small problem, I'm using the following statment at the end of my script to start the download:

header("Location: $url");

where $url is /files/test.wmv in our example above, It will just calls the file and starts the download, the question is:

How can I show the prompt for saving the file in which folder in the user's PC? because currently it'll just save the file in the temp internet folder

I want to give my users the ability to save the file in a folder they want.

Thanks in advance
 
change
Code:
header("Location: $url");
to:
Code:
if (is_file($url)):
   header("Pragma: public");
   header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
   header("Cache-Control: private",false);
   header("Content-Type: 'application/octet-stream'");
   header('Content-Disposition: attachment; filename="test.wmv"');
   header("Content-Transfer-Encoding: binary");
   header('Content-Length: '.filesize($url));
   set_time_limit(0);
   @readfile($abs_item) or die("cannot output file");
else:
   die("the requested file does not exist");
endif;
 
thanks jpadie for your help but why you put the variable $abs_item ? Its not working !
 
copy and paste went wrong (pilot error).

that line should be
Code:
@readfile($url) or die("cannot output file");
 
Thanks again jpadie for your help ;)

Tts not working! It returned:

the requested file does not exist

What the $url should be?

Currently it the full path to the file

e.g.

/dir1/dir2/dir3/test.wmv

where my script download.php is located above dir1
 
Help please, its urgent because my script is LIVE already
 
I think the people who know are enjoying a break. Don't know if this link will shed any light.


Bit like the blind leading the blind.

Have you tried something like:
<?php
header("location: ./Dir1/Dir2/Dir3/test.wmv");
?>

I cannot seem to find reference to what all my dots do in my case:

("location: .../index.php");

Hope you get there, I know what its like. Maybe it will rain and they will be back. Regards.
 
ZOR thanks for passing ;) but still its not solved :(
 
readfile() ought to take just about any valid path you give it. The only isue you may have is startingthe path off with a single /. I'm not sure how readfile determines if that is an absolute path from the root directory or a URL starting at the base folder.

Try passing it "/files/test.wmv" and, if that doesn't work, prepend " to it. Additionally, when you put this script into production your going to want to change this line:
Code:
header('Content-Disposition: attachment; filename="test.wmv"');

-T

 
the $url is a unc path name or any other valid uri. normal file naming/locating rules apply.

so if the file is called test.wmv and is in a subdirectory of the running script the url would be:

$url = "subdirectory/test.wmv";

if it was one directory higher than the running script:
$url = "../test.wmv";

or you can of course use absolute paths.
 
Amazing how much more clearly you said that :) My pre-coffee attempt above looks nothing like what I was trying to say.

 
Thanx all for helping ;)

I found the problem :)

It was becaus of the first slash

/dir1/dir2/dir3/test.wmv

It should be

dir1/dir2/dir3/test.wmv

(",)
 
Back again ;)

I noticed its not working for files greater than 10MB :(

any work around ?!

Thanks in advance
 
it's probably a time out issue. add
Code:
set_time_limit(0);
at the start of the script.

if this doesn't work get rid of the "@" before the readfile as the issue is likely to be related to something else instead (and omitting the @ may give you a clue)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top