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

download a file problem! 1

Status
Not open for further replies.

MJB3K

Programmer
Jul 16, 2004
524
GB
Hi, i have this code. The dl var is getting filled from a link!

what im trying to do is make it pop up the download box, but i need to get application type for it to work, why doesn't it work? All the filetypes could be differnt!

Some could be .ppt files, some could be .php, .doc etc

Code:
<?php
global $f;
$f = $_GET['dl'];

$ext = substr($f,-3);

//echo "Filename: $f :: Extension: $ext";

switch($ext){
	case	"php":	$ct = "application/x-httpd-php"; break;
	case	"ppt":	$ct = "application/vnd.ms-powerpoint"; break;
}

// We'll be outputting a PDF
header('Content-type: "$ct"');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="$f"');

// The PDF source is in original.pdf
readfile('$f');
?>

This does not work!

any ideas on how to do this?

Regards,

Martin

Gaming Help And Info:
 
lol, sorry. well it doesn't do anything...

any reason's why not?

have you seen any examples on the net of how to make this sort of thing? or what would i search for??

any help??


Regards,

Martin

Gaming Help And Info:
 
It looks like you have a problem with quotes.

Instead of your code:
Code:
// We'll be outputting a PDF
header('Content-type: "$ct"');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="$f"');

// The PDF source is in original.pdf
readfile('$f');
Try:
Code:
// We'll be outputting a PDF
header('Content-type: ' . $ct);

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename=' . $f);

// The PDF source is in original.pdf
readfile($f);

I think the big culprit was the string " '$f' " as an argument to the readfile function. That would have meant you were trying to read in the file named '$f', not the file with the name that is the value of $f.

Ken
 
A good technique to know when trying to debug activity which involves headers is using telnet to fetch a page. This gives you the ability to see everything the script is doing, not just the main content the script output.

See section 2.6 of my FAQ titled "Debugging PHP code" in this forum: faq434-2999


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top