上传文件时获取base64编码

上传文件时获取base64编码

问题描述:

I am trying to get the base64 encoding for a file when uploading in PHP using:

$sound = base64_encode( file_get_contents( $_FILES["sound"]["tmp_name"] ) );

but it's returning:

Notice: file_get_contents(): send of 8192 bytes failed with errno=104 Connection reset by peer

Is it possible to do this without saving the file to the server?

我正在尝试使用以下代码在PHP上传时获取文件的base64编码: p> \ n

  $ sound = base64_encode(file_get_contents($ _FILES [“sound”] [“tmp_name”])); 
  code>  pre> 
 
 

但它正在返回: p>

注意:file_get_contents():8192个字节的发送失败,errno = 104连接由peer重置 p> blockquote> 是否可以在不将文件保存到服务器的情况下执行此操作? p> div>

It looks like the filename is too long. Please check the length of the string you are passing to file_get_contents:

echo strlen($_FILES["sound"]["tmp_name"]));

As far as I feel your server might be configured improperly. Maybe you need to check the temp path for file uploads if it's not too long.