Jump to content

[SOLVED] header file output


hellonoko

Recommended Posts

I am using the below code to download a file that is stored in a obfuscated matter as what it actually is when downloaded.

 

	
header('Content-type: application/octet-stream');

header("Content-Disposition: attachment; filename="$name"");

readfile("$file");

 

When I have the second line written as:

 

	header('Content-Disposition: attachment; filename="bigpicture.jpeg"');

 

It works fine.

 

However when I try to change it around so that I can use $name which contains the actual name the file should be saved as the code does not work or simply downloads as download.php  the name of the download script.

 

How do I properly insert my $name variable?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/130149-solved-header-file-output/
Share on other sites

You can either do this:

 

header("Content-Disposition: attachment; filename=\"$name\"");

 

Or this:

 

header('Content-Disposition: attachment; filename="' . $name . '"');

 

The reason it's not working for you is because you can only put variable names inside double-quoted strings, not single-quoted strings.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.