dongyu4455 2016-01-23 01:21
浏览 65
已采纳

从mysql数据库上传和检索图像[重复]

This question already has an answer here:

I've got a small problem. I'm trying to save image, and retrive it from a database table. I've got a table with BLOB column, where images are saved.

Here is the script:

INSERT INTO male_users (image) VALUES ('$image')

And everything works fine, image is saved in database. But then i try to retrive it by this code:

echo " Image: <img src='" . $row["image"]. "'  />"

But image is not displaying there is only an image name, for example: "DSC0123.jpg", and thats all.

Thanks for help in advance! Best regards

</div>
  • 写回答

1条回答 默认 最新

  • douruduan8812 2016-01-23 01:34
    关注

    It's not best practice to store an image in a database, as the database will get very big, and slow. It's better if you just store the path to the image file in the server.

    You can upload images and save them in your server very easily with PHP. Since it's out of the scope of this question I'll leave you some tutorials:

    https://davidwalsh.name/basic-file-uploading-php http://www.w3schools.com/php/php_file_upload.asp

    And to answer your actual question, you're not saving the image, but the image name, you should use $_FILE and not $_POST when we're dealing with file uploads in PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题