You must set headers before you write and the first write causes the headers to be output.
Attach a file by drag & drop or click to upload