hellonoko Posted October 26, 2008 Share Posted October 26, 2008 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 Quote Link to comment Share on other sites More sharing options...
ratcateme Posted October 26, 2008 Share Posted October 26, 2008 you need to escape the "s like this header("Content-Disposition: attachment; filename=\"$name\""); Scott. Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted October 26, 2008 Share Posted October 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.