[英]Line feed in base64 encoded data
In a server sided script I am using the following PHP code to encode an image: 在服务器端脚本中,我正在使用以下PHP代码对图像进行编码:
$handle = fopen($imageSrc,'r');
$file_content = fread($handle,filesize($imageSrc));
fclose($handle);
$encoded = base64_encode($file_content);
echo $encoded;
When I read the file through a webservice it has the length 9309 bytes which is an invalid length for base64 encoded data. 当我通过Web服务读取文件时,文件的长度为9309字节,这对于base64编码数据来说是无效的长度。 Examining the data, I found out that the value last byte is 10 (LF).
检查数据,我发现最后一个字节的值是10(LF)。 Right now I am cropping the last byte away in my webservices before decoding the data.
现在,在解码数据之前,我正在裁剪Web服务中的最后一个字节。 Is there a clean way to avoid the LF character to be sent?
有没有一种干净的方法可以避免发送LF字符?
I'm not sure what is causing this, but having debugged similar issues in the past, I would assume that there is something below the echo
causing a \\n
to be output. 我不确定是什么原因造成的,但是在过去调试过类似的问题之后,我会认为
echo
下面有一些东西会导致\\n
输出。
To test this, put a die();
为了测试这个,放一个
die();
directly after the echo
. echo
后直接。 If my theory is correct, you can either just leave the die();
如果我的理论是正确的,则可以只离开
die();
, or (better) move it progressively downwards in the execution flow until you find whatever is causing the \\n
to be output. ,或(更好)在执行流程中将其逐渐向下移动,直到找到导致
\\n
输出的任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.