从数据库blob类型下载文档文件

时间:2018-03-29 20:03:15

标签: php mysqli blob

这是我的上传

try {
$xmlWriter  = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');

$xmlWriter -> save($path.$file);

}finally{

$fileup = file_get_contents($path.$file);

$upload = base64_encode($fileup);

$pdo = new PDO("mysql:host=localhost;dbname=db", "root", "Password");

$statement = $pdo->prepare("insert into upload_file(file_name,C_name) 
values(?,?)");

$statement->bindParam(1,$upload);

$statement->bindParam(2,$name);

$statement->execute();

}

here's my download

    $files =  mysqli_query($conn,"SELECT*FROM upload_file WHERE C_name = '$name';");

$result = mysqli_fetch_assoc($files);

$con = $result['file_name'];

$content = base64_decode($con);

$filenamed = $result['C_name'];

header("Content-Disposition: attachment; filename=\"$filenamed\"");

header('ContentType:application/vnd.openxmlformatsofficedocument.wordprocessingml.document');

print $content;

exit;

0 个答案:

没有答案