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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.