php从数据库生成图像但首先生成换行符[重复]

This question already has an answer here:

header("Content-type: ".$response->strExtension.""); 
header("Content-length: ".$response->intSize.""); 
header("Content-Disposition: attachment; filename=".basename( $response->strFileName ).""); 
exit(base64_decode($response->binFile));

Im generating an image using the above code. But when checking the generated image using notepad++ it has a newline before the data itself so I get error in opening the image. Like below:

enter image description here

How can I make sure that the generate file has no space or new lines.

Tried trimming the echoed base64_decode($response->binFile) but it didnt do the job. No other echo are executed in this scenario.

</div>

You can try some of the approaches here for removing whitespaces in your base64: remove whitespaces from base64 encoded string when posting . Hope this helps! :)