Hướng dẫn how to display image from database in html - cách hiển thị hình ảnh từ cơ sở dữ liệu trong html

Tôi đã tạo cơ sở dữ liệu MySQL với bảng bằng PHPMyAdmin. Tôi đã tạo bảng này bằng cột Blob để giữ tệp JPEG.

Tôi có vấn đề liên quan đến biến PHP $result ở đây.

Mã của tôi cho đến nay: (catalog.php):

<body>
<?php
  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=1";
  $result = mysql_query("$sql");
  mysql_close($link);

?>
<img src="" width="175" height="200" />
</body>

Làm thế nào tôi có thể nhận được kết quả $ $ từ PHP vào HTML để tôi có thể hiển thị nó trong thẻ <img>?

Hướng dẫn how to display image from database in html - cách hiển thị hình ảnh từ cơ sở dữ liệu trong html

hỏi ngày 17 tháng 10 năm 2011 lúc 11:20Oct 17, 2011 at 11:20

6

Bạn không thể. Bạn cần tạo một tập lệnh PHP khác để trả về dữ liệu hình ảnh, ví dụ: getImage.php. Thay đổi catalog.php thành:

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>

Sau đó getImage.php là

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>

Hướng dẫn how to display image from database in html - cách hiển thị hình ảnh từ cơ sở dữ liệu trong html

Đã trả lời ngày 17 tháng 10 năm 2011 lúc 11:29Oct 17, 2011 at 11:29

Hướng dẫn how to display image from database in html - cách hiển thị hình ảnh từ cơ sở dữ liệu trong html

Daiscogdaiscogdaiscog

10,8K5 Huy hiệu vàng49 Huy hiệu bạc61 Huy hiệu Đồng5 gold badges49 silver badges61 bronze badges

7

Về mặt kỹ thuật, bạn cũng có thể đặt dữ liệu hình ảnh vào thẻ IMG, sử dụng URI dữ liệu.

<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />

Có một số trường hợp đặc biệt mà điều này thậm chí có thể hữu ích, mặc dù trong hầu hết các trường hợp, bạn nên phục vụ hình ảnh thông qua một kịch bản riêng biệt như Daiscog gợi ý.

Đã trả lời ngày 17 tháng 10 năm 2011 lúc 14:27Oct 17, 2011 at 14:27

Hướng dẫn how to display image from database in html - cách hiển thị hình ảnh từ cơ sở dữ liệu trong html

Ilmari Karonenilmari KaronenIlmari Karonen

48.5K9 Huy hiệu vàng91 Huy hiệu bạc152 Huy hiệu Đồng9 gold badges91 silver badges152 bronze badges

1

Bạn cần truy xuất và đưa thông tin vào những gì bạn cần.

while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}

Đã trả lời ngày 17 tháng 10 năm 2011 lúc 11:27Oct 17, 2011 at 11:27

Hướng dẫn how to display image from database in html - cách hiển thị hình ảnh từ cơ sở dữ liệu trong html

James Williamsjames WilliamsJames Williams

4.1911 Huy hiệu vàng18 Huy hiệu bạc35 Huy hiệu Đồng1 gold badge18 silver badges35 bronze badges

thêm

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
0 sau mysql_query ();

HTML

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
1 của bạn

Đã trả lời ngày 17 tháng 10 năm 2011 lúc 11:39Oct 17, 2011 at 11:39

PunitpunitPunit

1.1121 Huy hiệu vàng8 Huy hiệu bạc14 Huy hiệu đồng1 gold badge8 silver badges14 bronze badges

1

Tải lên hình ảnh/video vào cơ sở dữ liệu và hiển thị nó bằng PHP là cách tải hình ảnh lên cơ sở dữ liệu và tìm nạp nó từ cơ sở dữ liệu. Sử dụng mã PHP, người dùng tải lên hình ảnh hoặc video mà họ đang nhập vào cơ sở dữ liệu một cách an toàn và hình ảnh nên được lưu vào một vị trí cụ thể bằng cách tìm nạp các hình ảnh này từ cơ sở dữ liệu. Nếu bất kỳ trang web nào chứa chức năng để tải lên hình ảnh/ Video với một số chi tiết, sau đó bằng cách sử dụng mã này, chúng tôi sẽ tải hình ảnh vào cơ sở dữ liệu của bạn và liệu bạn có muốn xác định những gì người đó phải được tải lên hay không. Và bằng mã này, hình ảnh được tải lên nơi lưu trong hệ thống của bạn nơi bạn được cung cấp vị trí.
If any of the websites contain the functionality to upload images/videos with some detail, then by using this code we will upload the image into your database and whether you would like to ascertain what the person has got to be uploaded. And by this code the image which is uploaded that where save in your system where you are given the location.

Cách tiếp cận: Đảm bảo bạn đã cài đặt XAMPP hoặc WAMP Server trên máy của bạn. Trong hướng dẫn này, chúng tôi sẽ sử dụng máy chủ WAMP. Make sure you have XAMPP or WAMP server installed on your machine. In this tutorial, we will be using the WAMP server.

1. Tạo cơ sở dữ liệu: Đầu tiên, chúng tôi sẽ tạo một cơ sở dữ liệu có tên ‘GeekSforGeeks. Bạn có thể sử dụng cơ sở dữ liệu hiện tại của mình hoặc tạo một cơ sở mới.First, we will create a database named ‘geeksforgeeks‘. You can use your existing database or create a new one.

Tạo cơ sở dữ liệu Geekforgeeks

2. Tạo bảng: Tạo một bảng có tên ‘Hình ảnh‘. Bảng chứa hai trường: & nbsp;: Create a table named ‘image‘. The table contains two fields: 

  • ID - int (11)
  • Tên tệp - Varchar (100)

ID nên được tăng tự động (AI). Cấu trúc bảng của bạn sẽ trông như thế này:Auto incremented(AI). Your table structure should look like this:

cấu trúc bảng của hình ảnh ”

Hoặc bạn có thể tạo một bảng bằng cách sao chép và dán mã sau vào bảng SQL của phpmyadmin của bạn.you can create a table by copying and pasting the following code into the SQL panel of your PHPMyAdmin.

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Để làm điều này từ bảng điều khiển SQL, hãy tham khảo ảnh chụp màn hình sau.

Hướng dẫn how to display image from database in html - cách hiển thị hình ảnh từ cơ sở dữ liệu trong html

Tạo một bảng ‘hình ảnh” từ bảng điều khiển SQL

Chúng tôi sẽ sử dụng Bootstrap ở đây để sử dụng điều khiển biểu mẫu Bootstrap. Dưới đây là mã bao gồm liên kết CDN bootstrap trong phần đầu của mã HTML.

Tạo thư mục và tệp:

Bây giờ chúng tôi sẽ tạo một thư mục có tên là hình ảnh. Các tệp được khách hàng tải lên trên máy chủ sẽ được lưu trữ trong thư mục này. Tạo index.php và style.css. Giữ thư mục dự án chính của bạn (ví dụ tại đây .. tương ứng. Cấu trúc thư mục sẽ trông như thế này:image“. The files uploaded by the client on the server will be stored in this folder. Create index.php and style.css. Keep your main project folder (for example here.. GeeksForGeeks) in the “C://wamp64/www/“, if you are using WAMP or “C://xampp/htdocs/” folder if you are using the XAMPP server respectively. The folder structure should look like this:

Cấu trúc thư mục

Chương trình: Bây giờ, chúng tôi sẽ tạo biểu mẫu HTML để tải lên các tệp hình ảnh (bạn có thể tải lên bất kỳ loại tệp nào như .pdf hoặc .mp4) và sẽ hiển thị hình ảnh đã tải lên. Now, we will create an HTML form for uploading image files (you can upload any type of file like .pdf or .mp4) and will display the uploaded image.

  • Mã HTML: & NBSP;

HTML

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
2

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
4
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
7
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
1
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
2221
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
7
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
8
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
0
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
1__

<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
8
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
7
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
2
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
6
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
7
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
9
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
3
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
4
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
9
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
6

upload_max_size = 100M
post_max_filesize = 100M
4
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
6
upload_max_size = 100M
post_max_filesize = 100M
7
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
9
upload_max_size = 100M
post_max_filesize = 100M
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

C:\wamp64\bin\apache\apache2.4.27\bin
1
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3__

upload_max_size = 100M
post_max_filesize = 100M
4
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
8
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
6
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

upload_max_size = 100M
post_max_filesize = 100M
4
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
6
upload_max_size = 100M
post_max_filesize = 100M
7
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
9
upload_max_size = 100M
post_max_filesize = 100M
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

C:\wamp64\bin\apache\apache2.4.27\bin
1
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3__

upload_max_size = 100M
post_max_filesize = 100M
4
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
8
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
6
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
8
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
3
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
8
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
6
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

C:\wamp64\bin\apache\apache2.4.27\bin
1
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
00
upload_max_size = 100M
post_max_filesize = 100M
7
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
03

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
3
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
6
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
7
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
30
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
33
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
34

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
36
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
37
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
39
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
36
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
43
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
45
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
46

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
54

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
48
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
49
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
51
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
52

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
33
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
34

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
63

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
54

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
8
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
6
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
8
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
2
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
8
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
4
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

Giải thích mã PHP: & NBSP;

  • Trước tiên chúng tôi chọn các bản ghi từ bảng trong biến $ Truy vấn.
  • Sau đó, kết quả $ sẽ thực thi truy vấn.
  • Mặc dù vòng lặp được sử dụng để tìm nạp tất cả các bản ghi trong dữ liệu $ để tìm nạp hình ảnh từ cơ sở dữ liệu.
  • Và cuối cùng, các hình ảnh được định sẵn được hiển thị với sự trợ giúp của thẻ. Trong thẻ, chúng tôi đang chuyển vị trí của tệp được tải lên trên máy chủ và tên của tệp hình ảnh trong cơ sở dữ liệu của chúng tôi.
  • Mã CSS: The Style.css là tệp tạo kiểu biểu mẫu thành một thiết kế mới và mã được đưa ra dưới đây. & NBSP; & nbsp; The style.css is the file that styles the form into a new design and the code is given below. 
     

CSS

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
76

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
78
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
80
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
82
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
83
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
80
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
82
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
88

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
63

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
90

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
92
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
94
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
97
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
98
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
00
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
03
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
00
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
78
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
09
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
10
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
13
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
15
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
16
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
17
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
63

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
20

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
92
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
94
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
78
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
09
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
10
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
63

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
33

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
92
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
37
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
97
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
98
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
00
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
83
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
48
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
78
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
53
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
63

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
56

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
13
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
15
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
16
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
17
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
92
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
65
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
68
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
70
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
63

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
78
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
79
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
48
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40stylesheet file you should create another file in .css format and save it in the place where the main file is to be saved. The form created with the help of the POST method and the enctype=”multipart/form-data”is the action which encodes the files and allows you to send them through POST.
Now we are working on the PHP code for the transfer of the image from any folder of the system in a particular folder which you are mentioning and storing it into the database as a directory.
 

  • Bạn có thể sao chép mã trên và đề cập trực tiếp vào mã chính hoặc tạo một liên kết giống nhau trong mã HTML và đính kèm với mã chính được đưa ra dưới đây. Như đã đề cập rằng nếu bạn liên kết tệp bảng kiểu, bạn nên tạo một tệp khác ở định dạng .CSS và lưu nó ở nơi lưu tệp chính sẽ được lưu. Biểu mẫu được tạo với sự trợ giúp của phương thức POS hình ảnh từ bất kỳ thư mục nào của hệ thống trong một thư mục cụ thể mà bạn đang đề cập và lưu trữ nó vào cơ sở dữ liệu dưới dạng thư mục. & NBSP; The PHP code is for the uploading images, the file name is saved with the index.php, you can also save it with another name as you prefer. 
     

Mã PHP: Mã PHP dành cho hình ảnh tải lên, tên tệp được lưu bằng index.php, bạn cũng có thể lưu nó bằng một tên khác như bạn thích. & Nbsp; & nbsp;

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
73

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
74
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
75

PHP

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
76
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
80
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
81
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
82
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
83
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
84
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
85

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
87
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
89
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
83$result2__292929293____294

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
96
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
89
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
83$result2
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
92____
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
029____294

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
05
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
07
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
08
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
87
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
12
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
13
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
14
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
15
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
16
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
15
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
15
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
20
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
21

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
28
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
12
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
15
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
23
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
21

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
23
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
25
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
80
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
35
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
96
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
15
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
05
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
39

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
41
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
42
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
45
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
46
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
47

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
63

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
63

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
54

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
41
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
50
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40
The following are the explanation to create the PHP code which is the following: 

  • Giải thích: Sau đây là giải thích để tạo mã PHP như sau: & nbsp;
  • Error_Reporting (0) là để nhận lỗi 0 trong khi mã PHP đang chạy.
  • $ _files làm việc phía sau hiện trường. Nó đang được sử dụng để tải lên các tệp thông qua phương thức bài HTTP và giữ các thuộc tính của các tệp.
  • $ fileName là một tên được sử dụng để xác định duy nhất một tệp máy tính được lưu trữ trong hệ thống tệp.
  • $ tempname được sử dụng để sao chép tên gốc của tệp được tải lên cơ sở dữ liệu dưới dạng tên TEMP nơi hình ảnh được lưu trữ sau khi tải lên.“./image/” is the folder name where the image is to be saved after the upload. And the $filename is used for fetching or uploading the file.
  • $ Thư mục xác định đường dẫn của hình ảnh được tải lên vào cơ sở dữ liệu đến thư mục nơi bạn muốn được lưu trữ. Các. Và tên tệp $ được sử dụng để tìm nạp hoặc tải lên tệp.
  • $ dB, dòng cơ bản cho bất kỳ mã PHP nào để kết nối với cơ sở dữ liệu.image to the variable filename.
  • $ SQL được sử dụng để chèn hình ảnh vào cơ sở dữ liệu của hình ảnh tên bảng vào tên tệp biến.
  • Bây giờ, hãy để di chuyển hình ảnh được tải lên vào thư mục có tên là hình ảnh. Thư mục có tên hình ảnh được lưu vào thư mục WAMP hoặc XAMPP có trong C Drive vào thư mục WWW.

Kết hợp các mã trên: Mã cuối cùng tải hình ảnh lên MySQL bằng Php được theo sau. & NBSP; & NBSP; The final code of upload the image into MySQL using PHP is as followed. 
 

  • Chương trình: Tên tệp: index.php Tệp này kết hợp mã HTML và PHP. & Nbsp; & nbsp; This file combines the HTML and PHP code. 
     

PHP

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
73

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
74
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
75

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
76
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
80
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
81
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
82
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
83
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
84
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
85

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
87
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
89
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
83$result2__292929293____294

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
96
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
89
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
83$result2
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
92____
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
029____294

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
05
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
07
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
08
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
87
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
12
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
13
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
14
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
15
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
16
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
15
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
15
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
20
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
21

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
23
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
25
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
28
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
12
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
15
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
23
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
21

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
80
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
35
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
96
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
15
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
05
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
39

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
41
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
42
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
45
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
46
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
47

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
41
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
50
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
63

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
63

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
54

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
2

while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
40

while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
41

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
43

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
45
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
0
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
47
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
3
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
49
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
6
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
7

while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
52

while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
53

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
55
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
59
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
6
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
61
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
9
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
63
upload_max_size = 100M
post_max_filesize = 100M
2
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

upload_max_size = 100M
post_max_filesize = 100M
4
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
67
upload_max_size = 100M
post_max_filesize = 100M
7
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
9
upload_max_size = 100M
post_max_filesize = 100M
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

C:\wamp64\bin\apache\apache2.4.27\bin
1
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
73
upload_max_size = 100M
post_max_filesize = 100M
7
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
9__76

upload_max_size = 100M
post_max_filesize = 100M
4
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
85

upload_max_size = 100M
post_max_filesize = 100M
4
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
67
upload_max_size = 100M
post_max_filesize = 100M
7
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
9
upload_max_size = 100M
post_max_filesize = 100M
9
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

C:\wamp64\bin\apache\apache2.4.27\bin
1
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
93
upload_max_size = 100M
post_max_filesize = 100M
7
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
9____103

upload_max_size = 100M
post_max_filesize = 100M
4
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
85

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
05

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
85

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
55
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
30
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
73

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
15
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
38
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
39
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
40

Is

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
27
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
28
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
29
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
30$result
<img src="data:image/jpeg;base64,<?php echo base64_encode( $image_data ); ?>" />
39

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
54

upload_max_size = 100M
post_max_filesize = 100M
4
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
36
CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
37
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
5

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<?php

  $id = $_GET['id'];
  // do some validation here to ensure id is safe

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("dvddb");
  $sql = "SELECT dvdimage FROM dvd WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['dvdimage'];
?>
73

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
63

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
54

<body>
<img src="getImage.php?id=1" width="175" height="200" />
</body>
9
while($row = mysql_fetch_array($result)) {
 echo "img src='",$row['filename'],"' width='175' height='200' />";
}
85

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
47

CREATE TABLE IF NOT EXISTS `image` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `filename` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
48

  • Đầu ra: Cuối cùng, bạn sẽ có thể tải hình ảnh lên cơ sở dữ liệu và hiển thị nó bằng cách tìm nạp chúng từ cơ sở dữ liệu. & NBSP; Finally, you should be able to upload the images to the database and display it by fetching them from the database.
     

Hướng dẫn how to display image from database in html - cách hiển thị hình ảnh từ cơ sở dữ liệu trong html

đầu ra

Kết luận: Hình ảnh được tải lên vào cơ sở dữ liệu với mã PHP rất đơn giản và được sử dụng cho các mục đích khác nhau. Mã này giúp tải lên hình ảnh và sau đó tải hình ảnh vào cơ sở dữ liệu và có thể được hiển thị trong một thư mục khác. Một điều bạn nên lưu ý là khi bạn đang chạy chương trình này, có khả năng hình ảnh không được tải lên nhiều hơn 2 MB vì ​​chương trình PHP đã đặt giá trị mặc định của việc tải lên hình ảnh 2 MB và đăng hình ảnh 8 MB. Để vượt quá kích thước tải lên hình ảnh, bạn nên làm theo các bước sau: & nbsp; The uploaded image into the database with the PHP code is simple and used for various purposes. The code helps to upload the image and then uploaded the image into the database and can be shown in another folder.
One thing you should note is that when you are running this program there should be a possibility that the image is not uploaded more than 2 MB because the PHP program has set the default value of uploading an image of 2 MB and posting the image of 8 MB. For exceeding the size of uploading the image you should follow the following steps:
 

  • Đầu tiên, mở ổ C, sau đó mở thư mục WAMP hoặc XAMPP Server.
  • Sau đó mở thư mục bin.bin folder.
  • Mở thư mục phiên bản PHP (thư mục PHP 5.6.31) (vui lòng lưu ý rằng nếu bạn có phiên bản PHP khác, bạn cũng nên mở nó)
  • Sau đó tìm kiếm php.ini. Mở nó và sau đó tìm kiếm hai biến và thay đổi với chúng. Các biến là: & nbsp; & nbsp;php.ini. Open it and then search the two variables and change with them. The variables are: 
     
upload_max_size = 100M
post_max_filesize = 100M
  • Lưu với sự thay đổi này và sau đó mở & nbsp;
C:\wamp64\bin\apache\apache2.4.27\bin
  • và tìm kiếm tệp php.ini. Thay đổi điều tương tự mà ở trên đề cập.php.ini file. Change the same thing which is above mention.
  • Khởi động lại máy chủ WAMP hoặc XAMPP và sau đó chạy mã.

PHP là ngôn ngữ kịch bản phía máy chủ được thiết kế dành riêng cho phát triển web. Bạn có thể học PHP từ đầu bằng cách làm theo hướng dẫn PHP và các ví dụ PHP này.


Làm cách nào để có được một hình ảnh từ cơ sở dữ liệu?

Tệp PHP xử lý quá trình tải lên hình ảnh và quá trình chèn cơ sở dữ liệu. Kiểm tra xem người dùng chọn một tệp hình ảnh để tải lên. Truy xuất nội dung của tệp hình ảnh bằng TMP_NAME bằng hàm PHP File_Get_Contents (). Chèn nội dung nhị phân của hình ảnh vào cơ sở dữ liệu bằng PHP và MySQL.Retrieve the content of image file by the tmp_name using PHP file_get_contents() function. Insert the binary content of the image in the database using PHP and MySQL.

Làm thế nào truy xuất hình ảnh từ cơ sở dữ liệu MySQL và hiển thị trong thẻ HTML?

PHP $ id = $ _get ['id']; // Thực hiện một số xác thực ở đây để đảm bảo ID an toàn $ link = mysql_connect ("localhost", "root", ""); mysql_select_db ("dvddb"); $ sql = "chọn dvdimage từ dvd trong đó id = $ id"; $ result = mysql_query ("$ sql"); $ row = mysql_fetch_assoc ($ result); mysql_close ($ link); Tiêu đề ("Loại nội dung: hình ảnh/jpeg"); Echo ...$id = $_GET['id']; // do some validation here to ensure id is safe $link = mysql_connect("localhost", "root", ""); mysql_select_db("dvddb"); $sql = "SELECT dvdimage FROM dvd WHERE id=$id"; $result = mysql_query("$sql"); $row = mysql_fetch_assoc($result); mysql_close($link); header("Content-type: image/jpeg"); echo ...

Làm thế nào chúng ta có thể tìm nạp hình ảnh từ cơ sở dữ liệu trong PHP và hiển thị trong HTML?

Giải thích về mã PHP: Trước tiên chúng tôi chọn các bản ghi từ bảng trong biến $ Truy vấn. Sau đó, kết quả $ sẽ thực thi truy vấn. Mặc dù vòng lặp được sử dụng để tìm nạp tất cả các bản ghi trong dữ liệu $ để tìm nạp hình ảnh từ cơ sở dữ liệu. Và cuối cùng, các hình ảnh được định sẵn được hiển thị với sự trợ giúp của thẻ.first selecting the records from the table in the $query variable. Then the $result will execute the query. While loop is used to fetch all the records in the $data to fetch the image from the database. And finally, the fetched images are displayed with the help of the tag.

Làm thế nào hình ảnh tìm nạp từ cơ sở dữ liệu trong PHP và hiển thị trong div?

Làm thế nào hình ảnh tìm nạp từ cơ sở dữ liệu trong PHP và hiển thị trong Div ?..
Đã tạo hình ảnh bảng.Bây giờ hãy tạo tệp cấu hình để định cấu hình cấu hình tệp kết nối cơ sở dữ liệu.PHP ..
Tải lên hình ảnh..
Hình ảnh cấu trúc thư mục ..
Hình ảnh được chèn vào cơ sở dữ liệu ..
Hình ảnh được tải lên và chèn vào cơ sở dữ liệu ..
Hình ảnh được tìm nạp từ bảng cơ sở dữ liệu ..