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 Link to comment https://forums.phpfreaks.com/topic/130149-solved-header-file-output/ 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. Link to comment https://forums.phpfreaks.com/topic/130149-solved-header-file-output/#findComment-674895 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. Link to comment https://forums.phpfreaks.com/topic/130149-solved-header-file-output/#findComment-674896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.