栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用php将图像存储在mysql数据库中

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用php将图像存储在mysql数据库中

我找到了答案,对于那些在这里寻找相同事物的人,我是怎么做的。您不应该考虑将图像上传到数据库,而是可以将上传文件的名称存储在数据库中,然后检索文件名,并在要显示图像的任何位置使用它。

HTML代码

<input type="file" name="imageUpload" id="imageUpload">

PHP代码

if(isset($_POST['submit'])) {    //Process the image that is uploaded by the user    $target_dir = "uploads/";    $target_file = $target_dir . basename($_FILES["imageUpload"]["name"]);    $uploadOk = 1;    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);    if (move_uploaded_file($_FILES["imageUpload"]["tmp_name"], $target_file)) {        echo "The file ". basename( $_FILES["imageUpload"]["name"]). " has been uploaded.";    } else {        echo "Sorry, there was an error uploading your file.";    }    $image=basename( $_FILES["imageUpload"]["name"],".jpg"); // used to store the filename in a variable    //storind the data in your database    $query= "INSERT INTO items VALUES ('$id','$title','$description','$price','$value','$contact','$image')";    mysql_query($query);    require('heading.php');    echo "Your add has been submited, you will be redirected to your account page in 3 seconds....";    header( "Refresh:3; url=account.php", true, 303);}

显示图像的代码

while($row = mysql_fetch_row($result)) {    echo "<tr>";    echo "<td><img src='uploads/$row[6].jpg' height='150px' width='300px'></td>";    echo "</tr>n";}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/415247.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号