PHP MYSQL PDO BLOB上载始终为空零字节
这是我的上传代码:PHP MYSQL PDO BLOB上载始终为空零字节,php,mysql,image,pdo,Php,Mysql,Image,Pdo,这是我的上传代码: public function upload($id, $title, $year, $comments){ $imagedata = fopen($_FILES['up_images']['tmp_name'], 'rb'); $query = 'INSERT INTO uploads (uid, title, year, comments, image, image_name) VALUES (:uid, :title, :year, :comments
public function upload($id, $title, $year, $comments){
$imagedata = fopen($_FILES['up_images']['tmp_name'], 'rb');
$query = 'INSERT INTO uploads (uid, title, year, comments, image, image_name) VALUES (:uid, :title, :year, :comments, :image, :image_name)';
$statement = $this->db->prepare($query);
$statement->bindValue(':uid', $id);
$statement->bindValue(':title', $title);
$statement->bindValue(':year', $year);
$statement->bindValue(':comments', $comments);
$statement->bindValue(':image', $imagedata, PDO::PARAM_LOB);
$statement->bindValue(':image_name', $_FILES['up_images']['name']);
$statement->execute();
// return $imagedata
return $_FILES['up_images']['error'];
}
正如您所看到的,我返回了错误和实际的图像缓冲区
错误=0
返回的原始缓冲区包含所有原始图像数据
我的所有参数都通过并成功上传到MYSQL数据库,但图像数据从未通过:这是我的PHPmyadmin屏幕
以下是表格结构:
这是我的表格:
<form action="digest.php" method="POST" id="up_form" enctype="multipart/form-data">
<input id="up_acct" name="up_acct" type="text" placeholder="Your ID" value="<?php echo $_GET['up_acct']; ?>" />
<input id="up_title" name="up_title" type="text" placeholder=" Title" value="<?php echo $_GET['up_title']; ?>" />
<input id="up_year" name="up_year" type="text" placeholder="Year" value="<?php echo $_GET['up_year']; ?>" />
<input id="up_images" name="up_images" type="file" accept=".jpg,.jpeg,.png,.gif,.svg" />
<textarea id="up_comments" name="up_comments" placeholder="COMMENTS (optional)" cols="22" rows="5"><?php echo $_GET['up_comments']; ?></textarea>
<input type="submit" name="up_submit" id="up_submit" value="UPLOAD">
我试图上传的图像大小是80kb
远低于我的php.ini设置
我的文件转储显示所有有效数据,包括有效的临时目录、名称甚至大小
我是否缺少mysql上某种类型的模糊配置?php
此外-我无法存储文件路径名并从文件系统中检索-作为更大项目的一部分请检查forPDO::PARAM_LOB
--bindParam
(而不是bindValue
)需要的是文件指针,而不是文件内容
$imagedata = fopen($_FILES['up_images']['tmp_name'], 'rb');
$statement->bindParam(':image', $imagedata, PDO::PARAM_LOB);
正如您所提到的,通常认为在DB中存储图像不是一个好的做法,除非有非常明确的理由这样做,并且其缺点是众所周知的。如果您不能100%确定这是必要的,那么它可能不是。对于这种情况,它不应该是
bindParam
而不是bindValue
吗?@Dan--Anthony的注释与您相关,您不应该对PDO::PARAM LOB
使用bindParam
而不是bindValue
?