所以我正在使用一个将图像存储在数据库中的应用程序.你对此有何看法?我更像是一种在文件系统中存储位置的类型,而不是直接将它存储在数据库中.
您认为利弊是什么?
byte[]我的实体中有一些字段,例如:
@Entity
public class ServicePicture implements Serializable {
private static final long serialVersionUID = 2877629751219730559L;
// seam-gen attributes (you should probably edit these)
@Id
@GeneratedValue
private Long id;
private String description;
@Lob
@Basic(fetch = FetchType.LAZY)
private byte[] picture;
Run Code Online (Sandbox Code Playgroud)
在我的数据库架构上,字段设置为,BLOB所以这应该没问题.无论如何:每当我尝试插入图片或pdf时 - 没有什么比1mb这更大,我只接受这个
16:52:27,327 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 22001
16:52:27,327 ERROR [JDBCExceptionReporter] Data truncation: Data too long for column 'picture' at row 1
16:52:27,328 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not insert: [de.ac.dmg.productfinder.entity.ServicePicture]
16:52:27,328 ERROR [STDERR] …Run Code Online (Sandbox Code Playgroud) 有没有办法将pics(不是url,pic)插入到用phpmyadmin制作的MYSQL表中?如果有什么时候我想得到那张照片并将其插入页面,我该怎么办?:)
这是我上传的代码..但它不起作用..我使用了file_get_contents函数..上传图片
</head>
<body>
<form action="upload1.php" method="POST" enctype="multipart/form-data">
File:
<input type="file" name="image"/>
<input type="submit" value="Upload image" />
</form>
<?php
//connect to the database
$con = mysql_connect("localhost","root", "");
if(!$con)
{
die('Could not connect to the database:' . mysql_error());
echo "ERROR IN CONNECTION";
}
mysql_select_db("imagedatabase", $con);
//file properties
echo $file = $_FILES['image']['tmp_name'];
echo '<br />';
if(!isset($file))
echo "Please select an image";
else
{
$image = file_get_contents($_FILES['image']['tmp_name']);
echo $image_name = addslashes($_FILES['image']['name']); echo '<br \>';
echo $image_size = getimagesize($_FILES['image']['tmp_name']);
if($image_size == FALSE)
echo "That's not …Run Code Online (Sandbox Code Playgroud)