Save and output images using PHP and MySQL

Source: Internet
Author: User
During our website design and production process, it is more convenient to save images to the database than to save them as files. PHP and MySQL can easily implement the above functions. In this article, we will show you how to save images to the MySQL database and how to display images in the database.
Set Database
The difference between the text or integer fields used in the database and the fields used to save images is that the data volume to be saved is different. The MySQL database uses special fields to store large data volumes. The data type is BLOB.
MySQL database defines BLOB as follows: BLOB data type is a large binary object that can save a variable amount of data. BLOB has four types: TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. The difference is that the maximum data length that can be stored is different.
After introducing the required data types, we can use the following statement to create a data table for storing images.
Create table Images (PicNum int not null AUTO_INCREMENT primary key, Image BLOB );
Write Upload script
We will not introduce how to upload files here. For more information, see the related articles in taoba. Now, let's take a look at how to receive the uploaded files and store them in the MySQL database. The specific script code is as follows. We assume that the name of the file upload domain is Picture.
<? If ($ Picture! =
From: http://it.dayoo.com/news/detail.asp? News_id = 2085

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.