Jump to content

Problem with header() and output buffering!

Featured Replies

Hi. I have been using something similar to the following code, and it works fine.

 

$file = $HTTP_GET_VARS['file'];
header("Content-type: audio/x-mp3");
header("Content-Disposition: attachment; filename=$file.mp3");
readfile("$file.mp3");

 

But when I change it to this it doesn't work, because there is other output before header() is called. (The reason I want to remove the "\"s from $file is because strings with apostrophes inherit them for some reason, and the files I'm trying to read aren't found as a consequence.)

 

$file = $HTTP_GET_VARS['file'];

//This part causes the problem because it's before header() is called
$parts=explode("\",$file);
$first=$parts[0];
$second=$parts[1];
$whole=$first.$second;

header("Content-type: audio/x-mp3");//This is the line I get a parse error on
header("Content-Disposition: attachment; filename=$whole.mp3");
readfile("$whole.mp3");

 

Can ob_start and ob_end_flush be used to get around this. I've tried a few things, but it's not working. Can anyone help me?

  • Author

Ah, I've found the error of my ways! All I need do is replace:

 

$parts=explode("\",$file);
$first=$parts[0];
$second=$parts[1];
$whole=$first.$second;

 

with:

 

$whole=stripslashes($file);

 

This doesn't cause a problem, while the other one does for some reason. Fingers crossed that it won't! I was a bit too hasty with my post!

  • Author

Thanks for the tip! I'd actually enquired/searched on two other sites already, but didn't get any response, so decided to post here. I haven't been to http://www.phpbuilder.com before though.

Archived

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

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.