使用php(mysql)下载Blob文件

使用php(mysql)下载Blob文件,php,mysql,file,blob,Php,Mysql,File,Blob,我有一个MySQL数据库,其中有一个表调用,例如“ALL”可以包含一个blob文件 在表中,我存储了:文件大小、类型、名称和内容 当我尝试下载blob文件时,问题出现了 这是我的剧本: <?php $connection = mysqli_connect("localhost","user","password",dbname) or die('Database Connection Failed'); mysqli_set_charset($connection,'utf-8');

我有一个MySQL数据库,其中有一个表调用,例如“ALL”可以包含一个blob文件

在表中,我存储了:文件大小、类型、名称和内容

当我尝试下载blob文件时,问题出现了

这是我的剧本:

<?php
$connection =  mysqli_connect("localhost","user","password",dbname)
or die('Database Connection Failed');
mysqli_set_charset($connection,'utf-8');

$query = "SELECT * " ."FROM ALL WHERE id = '25'";
$result = mysqli_query($connection,$query) 
or die('Error, query failed');

 list($id, $user_made, $title, $category, $sub_category, $text, $type, $date, $time, $namefile1, $typefile1, $sizefile1, $contentfile1, $namefile2, $typefile2, $sizefile2, $contentfile2, $namefile3, $typefile3, $sizefile3, $contentfile3) = mysqli_fetch_array($result);
 echo $id . $namefile1 . $typefile1 . $sizefile1;
 header('Content-Length: '.$sizefile1);
 header('Content-Type: '.$typefile1);
 header('Content-Disposition: attachment; filename="'.$namefile1.'"');
 header('Content-Transfer-Encoding: binary');
 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');  
 ob_clean();
 flush();
 // echo $contentfile1;
 mysqli_close($connection);
 exit;
?>

但是页面只输出“$contentfile1”和“$id.$namefile1.$typefile1.$sizefile1”的回显

每个人都能帮我吗?
谢谢

在ob_clean之前添加此代码

    $context = stream_context_create();
    $file = fopen($filename, 'rb', FALSE, $context);
    while(!feof($file))
    {
       echo stream_get_contents($file, max_bytes_to_read);
    }
    fclose($file);

您可以在

获取有关流内容的更多信息。您需要的是文件的回显内容,而不是id或其他信息。您需要设置为标题的其他数据,如文件大小(内容长度)、文件类型、文件名等。Hank Aleksey,我已经解决了我的问题!再次感谢您可能的副本