You're opening $location using the append mode (>>) but you're trying to read from it. You're also not printing any HTTP header at all. And if you don't supply a MIME type, the browser won't know what to do with the data. What kind of data is this, and what do you want the browser to do with it?