每个人,即时运行在一些问题,现在,看看我无法控制的服务器或任何东西的内部情况,现在我不能使用base64编码的文件直接通过网站,因为当服务器提供内容的浏览器它有一个字符的限制对于这些任务,它会直接影响base64编码文件导致这些字符串的长度,所以我为一个系统创建了一个php脚本,它将已经存在的base64 pdf文件作为可下载文件提供给客户端,它的工作方式如下所示:
$reg = File::find($args->string('id')); //querying the file from database
$filename = $reg->filename; //the original file name
$base64 = $reg->file; //the base64 encoded file
$meta_type = explode(',', $base64) [0]; //getting the meta type of the file
$meta_type = str_replace('data:', '', $meta_type);
$meta_type = str_replace(';base64', '', $meta_type);
$file = explode(',', $base64) [1];
$file = base64_decode($base64); //decoding the base64 string
header('Content-Description: File Transfer');
header('Content-Type: ' . $meta_type);
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . (strlen($file)));
echo $file;这工作得很好,当我使用PDF文件,但当我尝试使用它的一些'xlsx'文件似乎工作,它下载文件,文件大小和所有似乎匹配的原始,但excel无法打开文件,做任何人有一个想法,我即时失踪? :)