gpt4 book ai didi

php - 将带有文本的图像上传到数据库php mysql

转载 作者:行者123 更新时间:2023-11-29 23:29:36 25 4
gpt4 key购买 nike

我目前有一个html表单,应该将文本和图像提交到数据库。我正在尝试使用一个提交按钮发布文本和图像。图像存储为斑点。该代码当前包含两个mysql_query函数,第一个用于文本,第二个对图像不起作用。当我点击表单提交按钮后,如何将表单数据(图像和文本)放入一个mysql_query函数中?我已经尝试了多种方法来放入一个mysql_query函数,但是我无法使其正常运行。或者,如果有人知道一个教程,该教程显示了如何使用出色的图像提交文本。

码:

    <?php //edit home.php slideshow headlines


if(isset($_POST['submita'])){
$linka = $_POST['linka'];
$titlea = $_POST['titlea'];
$contenta = $_POST['contenta'];
$thumba = $_POST['thumba'];

//first mysql_query function for text
mysql_query("INSERT INTO headlines2 (linka, titlea, contenta, thumba)VALUE('$linka','$titlea','$contenta','$thumba')");

//image blob content here

if(!isset($_FILES['imagea']))
{
echo 'Please select an image.';
}
else {
$imagea = addslashes(file_get_contents($_FILES['imagea']['tmp_name']));
$image_name = addslashes($_FILES['imagea']['name']);
$image_size = getimagesize($_FILES['imagea']['tmp_name']);

if($image_size==FALSE){
echo "That's not an image.";
} else {

//second mysql_query function imagea
if(!$insert = mysql_query("INSERT INTO headlines2 VALUES ('','$image_name','$imagea')"))
{
echo "Problem uploading image.";
}else{
/*$lastid = mysql_insert_id();
$lastid = $lastid - 10;
Your image:<br /><img src=get.php?id=$lastid />
*/
echo "Image uploaded. <br /> ";



}
}
}

//end image blob


echo "Posted";
header('location: admin.php?edit1=edit_home');

}else{
?>
<?php

?>
<form action="?edit1=edit_home" method="post"enctype="multipart/form-data">

<legend><h3>Update Headlines</h3></legend>
<p class="label"><label class="field">Headline Link (.php * File Ending Required)</label></p><input type="text" name="linka" />

<p class="label"><label class="field">Headline Title</label></p><input name="titlea"/>

<p class="label"><label class="field">Content</label></p><textarea name="contenta"></textarea>
<p class="label"><label class="field">Left Thumbnail on Slider</label></p><input name="thumba"/>

Image (Must be a jpeg*): <input type="file" name="imagea" />

<input type="submit" name="submita" value="Post!" />

</form>
<?php
}
?>

最佳答案

使用MySQL的LOAD_FILE()

mysql_query("INSERT INTO headlines2 VALUES ('','$image_name', LOAD_FILE('$imagea')"));

关于php - 将带有文本的图像上传到数据库php mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26661477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com