【发布时间】:2017-03-23 14:03:31
【问题描述】:
我正在尝试将图像直接插入到 oracle 数据库表中。在我的数据库中,我总是得到 [BLOB - 0B]。它不会将图像插入表中。我也没有收到任何错误。
<html>
<form action="save_img.php" method="post" enctype="multipart/form-data">
<input type="file" name="image"/>
<input type="submit"/>
</form>
</html>
<?php
include('config.php');
$fp = fopen($_FILES['image']['tmp_name'],'rb'); //read binary
try{
$stmt=$con->prepare("insert into images(photo) values(?)");
$stmt->bindParam(1,$fp,PDO::PARAM_LOB);
$con->errorInfo();
$stmt->execute();
}
catch(PDOEception $e){
echo($e->getMessage());
}
?>
【问题讨论】:
-
如果您必须将图像放入数据库表中,则在将文件发送到数据库之前
base64encode()。 -
当然,读取打开的文件而不是尝试将文件句柄发送到数据库也很有用。跨度>
标签: php html oracle pdo oracle12c