“ addimage.php”将图像添加到Mysql(table:question)
$question = mysqli_escape_string($conn,$_POST['question']); $file_temp = base64_encode( file_get_contents( $_FILES['image']['tmp_name'] ) ); $query = "INSERT INTO question(question_name, image)VALUES('$question','$file_temp');
我的HTML是:
<textarea rows="4" cols="50" name="question" required></textarea><br>
<input type="file" class="form-control" id="image" name="image" required><br>
“显示image.php”以显示数据库中的图像(表:问题)
<?php $query = "SELECT * FROM question";
$result = mysqli_query($conn, $query); ?>
<?php while ($row = mysqli_fetch_array($result)) { ?>
<tr><td> <?php echo $row['question_name']; ?></td>
<td> <?php echo "<img src='data:image/png;base64,$row[image]'/>"?></td></tr> <?php } ?>
以前在两个PHP页面中上传和显示均正常
现在,我想在“问题”表中检索图像并将它们插入到另一个表“测试问题”中,然后显示它们(需要工作)。
将图像从表“ question”插入表“ testquestion”也可以:
$query1 = "select id,question_name,image from question";
$result1 = mysqli_query($conn, $query1);
while ($row1 = mysqli_fetch_array($result1)) {
$id=$row1['id'];
$question_name=$row1['question_name'];
$image=$row1['image'];
//$file_temp = base64_encode( file_get_contents( $_FILES['".$image."' ]['tmp_name'] ) );
$query2 = "INSERT INTO testquestion(id,question_name, image)VALUES('$id','$question_name','$image')";
$result2 = mysqli_query($conn, $query2);
}
但是图像显示无法正常工作:
<?php $row = mysqli_query( $conn, "select id,question_name,image from testquestion"); while ( $result = mysqli_fetch_assoc($row) ) { echo '<img src="data:image/png;base64,'.base64_encode($result['image']).'" />'; }?>
有人可以帮我吗?
答案 0 :(得分:0)
$row = mysqli_query( $conn, "select id,question_name,image from testquestion");
while ( $result = mysqli_fetch_assoc($row) ) {
echo '<img src="data:image/png;base64,'.($result['image']).'" />';
}