PHP LongBlob Upload/Download 不处理图片
PHP LongBlob Upload/Download not working with pictures
我必须在我的数据库中存储大量文档,并且我设法使其与 PDF 一起使用。
例如,当我尝试上传 JPG 或 GIF 时,当我从下面的下载功能重新下载时,内容没有显示。
下载功能:
public function downloadFile($id) {
if($id!=null){
$sql = "SELECT * FROM document WHERE id = ?";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(1, $id);
$stmt->execute();
foreach ($stmt as $row) {
header("Content-length:".$row['taillefichier']);
header("Content-type:" . $row['typefichier']);
header("Content-Disposition: attachment; filename=".$row['nomfichier']);
echo $row['fichier'];
}
}
所以我找到了我自己问题的答案,我将post更新后的功能放在这里
public function downloadFile($id) {
if($id!=null){
$sql = "SELECT * FROM document WHERE id = ?";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(1, $id);
$stmt->execute();
foreach ($stmt as $row) {
header("Content-length:".$row['taillefichier']);
header("Content-type:".$row['typefichier']);
header("Content-Disposition: attachment; filename=".$row['nomfichier']);
header("Content-type:".$row['typefichier']);
ob_clean();
flush();
echo $row['fichier'];
}
}
}
在此处查看更多信息:
我必须在我的数据库中存储大量文档,并且我设法使其与 PDF 一起使用。 例如,当我尝试上传 JPG 或 GIF 时,当我从下面的下载功能重新下载时,内容没有显示。
下载功能:
public function downloadFile($id) {
if($id!=null){
$sql = "SELECT * FROM document WHERE id = ?";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(1, $id);
$stmt->execute();
foreach ($stmt as $row) {
header("Content-length:".$row['taillefichier']);
header("Content-type:" . $row['typefichier']);
header("Content-Disposition: attachment; filename=".$row['nomfichier']);
echo $row['fichier'];
}
}
所以我找到了我自己问题的答案,我将post更新后的功能放在这里
public function downloadFile($id) {
if($id!=null){
$sql = "SELECT * FROM document WHERE id = ?";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(1, $id);
$stmt->execute();
foreach ($stmt as $row) {
header("Content-length:".$row['taillefichier']);
header("Content-type:".$row['typefichier']);
header("Content-Disposition: attachment; filename=".$row['nomfichier']);
header("Content-type:".$row['typefichier']);
ob_clean();
flush();
echo $row['fichier'];
}
}
}
在此处查看更多信息: