使用PHP将图片插入数据库 [英] Insert picture into database using php

查看:54
本文介绍了使用PHP将图片插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个输入很多的表格(姓名,姓氏,图片,年龄..),我想将所有这些信息提交到我的数据库中,我知道如何通过简单的输入来做到这一点,但是带有图片我有问题 有谁可以帮助我吗 我的html文件是

hello i have a form with many input ( name, last name, picture,age..) and i want to submit all this information into my database , i know how to do it for a simple input but with the picture i have some problem can someone help me please my html file is

<form action="insertion.php" method="post" >
<table >
 <tr>
 <td><strong>Titre</strong></td>
 <td><input name="titre" type="text" value=""  /></td>
 </tr>
 <tr>
 <td><strong>Annee</strong></td>
 <td><input name="annee" type="number" value=""  /></td>
 </tr>
 <tr>
 <td><strong>Genre musical</strong></td>
 <td><input name="Gmusical" type="texte" value="" /></td>
 </tr>
 <tr>
 <td>
 <strong>Picture</strong>
 </td>
 <td>
 <input type="file" name="img"/>
 </td>
 </tr>
</table>
 <input type="submit" value="Submit "  />
</form>

我要插入数据库的文件insert.php是

my file insertion.php to sublmit into the database is

<?php
include("connexion.php");
$titre=$_POST['titre'];
$annee=$_POST['annee'];
$Gmusical=$_POST['Gmusical'];
$picture=$_POST['img'];

$req="INSERT INTO `cd`
(`titre`, `Annee`, `genremusical`, `Image`) 
VALUES 
 ('$titre','$annee','$Gmusical','$picture');";

            if (mysql_query($req))
            {
            echo "ok";
            }
            else 
            echo 'ko';
            }

推荐答案

通常,您不想在数据库中存储实际的BLOB(二进制大对象)数据类型.您将图像的路径存储在Web服务器上的某个位置.

Generally you do not want to store actual BLOB(binary large object) data types in a database. You store the path to the image, located somewhere on your web server.

因此,在图像"列中,您将存储路径"images/photo1103.jpg".

So in the column "Image", you would store the path "images/photo1103.jpg".

要显示照片: echo "<img src=". $image_query_fetch['Image'] .'" alt=\"\" />";

这篇关于使用PHP将图片插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆