Cách lưu trữ tệp pdf trong cơ sở dữ liệu mysql bằng nút js

5

 

    

7 
8_______5_______60

12

3456

1____324_______

        0

2

Tạo thư mục và tập tin

Bây giờ chúng ta sẽ tạo một thư mục có tên “pdf“. Các tệp do máy khách tải lên máy chủ sẽ được lưu trữ trong thư mục này. Tạo chỉ mục. php và phong cách. css. Giữ thư mục dự án chính của bạn (Ví dụ. GeekForGeek) trong “C. //wamp64/www/“, nếu bạn đang sử dụng WAMP hoặc “C. //xampp/htdocs/” nếu bạn đang sử dụng máy chủ XAMPP tương ứng. Cấu trúc thư mục sẽ giống như bên dưới

cấu trúc thư mục

Tạo biểu mẫu. Với biểu mẫu HTML, chúng tôi đang thu thập dữ liệu từ người dùng bằng cách bật. tập tin đính kèm pdf để tải lên

Biểu mẫu HTML

HTML code snippet: Below is the HTML source code for the HTML form. In the HTML
tag, we are using “enctype=’multipart/form-data” which is an encoding type that allows files to be sent through a POST method. Without this encoding, the files cannot be sent through the POST method. We must use this enctype if you want to allow users to upload a file through a form.

HTML




    2    3     4=    6     7=325_______9$host0

    325_______2_______326_______3 $host4_______327_______$host6$host0

1    2$host3 $host4=327_______3$host0

=5    2=7 =8=328_______0 $host4=328_______3 'localhost'4='localhost'6

'localhost'7'localhost'8=329_______0 ;1

1;3$host3;5

1    2$host3 $host4=327_______3$host0

=5    2=7 =8=1_______08 'localhost'4=1_______11

'localhost'7$host4=328_______3

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
16=1_______18

'localhost'7

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
20_______327_______
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
22
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
23

1;3$host3$host0

1    2$host3 $host4=327_______3$host0

=5    2=7 =8=1_______40 $host4=

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
43

'localhost'7'localhost'4=___

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
40
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
48=1_______50$host0

1;3$host3$host0

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
56;3$host3$host0

;3______325_______3$host0

Tải lên tệp PDF. Bây giờ chúng ta sẽ xem cách tải tệp PDF lên cơ sở dữ liệu. Trong đoạn mã dưới đây, khối đầu tiên xác minh rằng nút 'gửi' từ biểu mẫu đã được nhấp và nó xác minh rằng trường 'pdf_file' có tệp đính kèm bằng cách sử dụng hàm isset() của PHP

$_FILES là một mảng toàn cầu kết hợp hai chiều của các mục đang được tải lên thông qua phương thức HTTP POST. Hàm move_uploaded_file() dùng để upload file pdf lên server. Chúng tôi đang chuyển 2 giá trị, tên tệp tạm thời và thư mục nơi tệp sẽ được lưu trữ. Các tệp sẽ được lưu trữ trong thư mục “GeeksForGeeks/pdf/” mà chúng tôi đã tạo trước đó

PHP




    15_______7

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
66
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
67
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
69
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
70

 

1_______1_______72 =1_______67

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
76
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
77

 

1

7
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
66
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
81
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
83
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
84
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
76
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
86

1_______1_______88

=5

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
90 =1_______81
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
83
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
84
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
76
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
77

=5

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
99 =1_______81
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
83
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
84
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
05
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
77

 

=5

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
08
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
99
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
9
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
11
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
12
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
90
5

 

=5____5_______16 =

=5_______5_______19;

=5

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
22
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
23
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
6_______5_______9
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
16
5

1____325_______0

1_______5_______31

1_______1_______88

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
342

3_______5_______37_______326_______4=

3____5_______41

3____5_______43

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
44
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
45$host4=5_______48
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
49
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
50

'localhost'7

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
52_______5_______48
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
54

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
44_______5_______56

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
57_______5_______58

3____5_______60

=5____324_______

1____325_______0

        0

2

Tạo Bảng HTML và hiển thị các bản ghi

Chúng tôi sẽ lấy các bản ghi từ cơ sở dữ liệu và hiển thị chúng trong bảng HTML

hiển thị các bản ghi từ cơ sở dữ liệu

Đoạn mã HTML. Mã nguồn HTML cho bảng HTML trên như sau

HTML




    2$host3 $host4=5_______72$host0

    325_______2_______326_______3 $host4_______327_______5_______79$host0

1    2

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
83$host0

3____3_______325_______2_______5_______87$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89_______325_______2
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
91
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
92
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
91$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89_______325_______2
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
91
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
98
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
91$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89_______325_______2
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
91
04
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
91$host0

3____329_______3_______5_______87$host0

3____325_______2

13$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89_______15_______16
17

18
19
20 =
22;

18
19
26 =
28
29

18

18
32
33 =
35
36

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89____324_______2

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89____325_______2
41$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
57_______325_______2
45
46
17
48
45$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
57_______325_______2
45
46
17
56
45$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
57_______325_______2
45_______15_______46
17
64
45$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89_______329_______3
41$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89_______15_______16
17

18    0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89____324_______2

3____329_______3

13$host0

1;3_______5_______83

85

    ;3_______326_______3$host0

;3______326_______3$host0

mã PHP

Tiếp cận

Đầu tiên, chúng tôi đang chọn tất cả các cột từ bảng pdf_data và sau đó thực hiện truy vấn trong $squery

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);

Tiếp theo, chúng ta sẽ sử dụng vòng lặp while để tìm nạp tất cả các hàng của bảng và lưu trữ dữ liệu trong $result

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}

Dữ liệu tìm nạp bây giờ sẽ được hiển thị theo cột trong bảng HTML với sự trợ giúp của

Mã đầy đủ. Mã cuối cùng để tải tệp PDF lên cơ sở dữ liệu MySQL và hiển thị tất cả các bản ghi từ bảng bằng PHP như sau. Mã đầy đủ này bao gồm

  • mục lục. php
  • Phong cách. css
  • dbcon. php

PHP




94 
95
96

 

97

98____15_______99$host0

01

    324_______03_______324_______04 05

06______326_______0

    324_______03_______324_______04 0512$host0

14

15

    

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
37_______326_______4_______327_______20 2122$host0

1

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
37$host4=324_______28$host0

3

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
37_______326_______4=324_______34$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
443738 39

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89_______324_______41____325_______6 43    9$host0

18

4849

48

7
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
66
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
67
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
69
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
86

48

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
88

59____324_______60

59_______1_______72 =1_______67

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
7667

 

59_______15_______7

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
66
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
81
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
83
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
84
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
76
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
86

59____324_______78

59____324_______80

81_______1_______90 =

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
81
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
83
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
84
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
76
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
77

81_______1_______99 =

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
81
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
83
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
84
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
05
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
77

81

81____325_______01

81_______5_______08

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
99_______5_______9
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
11
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
12
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
90
5

81____325_______11

81_______5_______16 =

81____5_______19;

81

81____325_______20

81_______5_______22

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
23
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
6
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
9
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
16    27

 

    28

7     30
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
22    32

    33_______325_______34

18    36

    37_______5_______37_______326_______4=

    28____325_______42$host0

    44_______5_______45$host4_______327_______5_______48

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
49
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
50
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
52
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
48$host0

    54____325_______55

    44_______325_______57

    44_______325_______59

    37_______5_______60

    28

    28    0

    28____5_______31

    28

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
88

    282

    37_______5_______37_______326_______4=

    28____325_______77$host0

    44_______5_______45$host4_______327_______5_______48

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
49
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
50
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
52
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
48$host0

    54____325_______55

    44_______325_______57

    44_______325_______94

    37_______5_______60

    28

    28    0

81____325_______0

81____5_______31

81____1_______88

$host07______324_______2

    28_______5_______37____326_______4=

    28____325_______77$host0

    37_______5_______45$host4_______327_______5_______48

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
49
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
50
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
52
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
48$host0

    54____325_______55

    37_______325_______57

    37______326_______31

    28____5_______60

$host07______324_______

81____325_______0$host38

48____325_______0$host38

182

18

18_______5_______37$host4=326_______6$host0

48_______5_______37$host4=327_______3$host0

81_______326_______58____328_______0 $host4='localhost'3

$host63$host64_______329_______0 $host66'localhost'6$host0

48____326_______70

48_______5_______37$host4=327_______3$host0

81_______326_______58

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
08 $host66
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
11

$host63$host4=328_______3 $host86

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
18 $host88

48____5_______60

48_______5_______37$host4=327_______3$host0

81____326_______58

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
40

    37_______326_______4=___

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
43 $host66
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
40 =06
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
50$host0

48____5_______60

18____5_______60

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89____327_______14

3____327_______16

3

3

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
37_______326_______4=324_______34$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
44
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
37$host4=327_______28$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89_______5_______37$host4=327_______34$host0

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
57_______327_______37

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89_______5_______60

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89_______5_______37$host4=5_______72$host0

=46_______5_______37$host4=5_______79$host0

=52______327_______53

48____327_______55

81____327_______57

81____327_______59

81______327_______61

48____327_______63

48____327_______65

59____324_______

$host07_______327_______69 =

22;

$host07_______327_______74

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
23
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
6
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
9=69
5

 

$host07_______327_______81 =82=83 =84=74=86

59____324_______2

59____327_______90

81_______327_______92____327_______93 =83

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68=96=97

81_______327_______92____327_______93 =83

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68'localhost'03=97

81_______327_______92____327_______93 =83

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
68'localhost'10=97

59____328_______13

59____324_______

    33______325_______0

59____324_______2

48'localhost'21

=52______328_______23

18____5_______60

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
89_______5_______60

3____5_______60

1____5_______60

    

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
60

'localhost'34

'localhost'35

CSS




'localhost'36

 

'localhost'37

    328_______39_______328_______40'localhost'41;328_______43'localhost'40'localhost'41'localhost'46

    0

'localhost'48

    'localhost'50_______328_______51'localhost'40'localhost'53;

    'localhost'56_______328_______53;

    0

 

'localhost'60

 

'localhost'61

    'localhost'63_______328_______40'localhost'65;

    0

 

'localhost'68

 

'localhost'69

    'localhost'71_______328_______40'localhost'73;

    'localhost'76_______328_______40'localhost'78;

    'localhost'81_______328_______82;

    'localhost'39'localhost'40'localhost'87;

    0

'localhost'90

    'localhost'92_______328_______40'localhost'94 'localhost'95 'localhost'96;

    'localhost'43_______328_______40;01 ;02;

    'localhost'50_______328_______51'localhost'40'localhost'53;

    ;11_______328_______40'localhost'53;

    'localhost'56_______328_______53;

    ;20;21

    0

;23

    ;25_______328_______40;27;

    ;30'localhost'40;32;

    0

;35;36'localhost'40_______329_______38;39

PHP




;40

 

    $host ='localhost';

    

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
1 =
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
3;

    

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
6 =
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
8;

    

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
1 =;60;

 

    5_______6

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
7$host___
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
9_______1_______1
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
9
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
6
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
9
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
1
5

 

    

7
8_______5_______60

12

3456

1____324_______

        0

2

đầu ra. Cuối cùng, bạn sẽ có thể tải lên các tệp pdf và hiển thị các bản ghi từ cơ sở dữ liệu trên cùng một trang

Cách lưu trữ tệp pdf trong cơ sở dữ liệu mysql bằng nút js

tải lên pdf và hiển thị

Trong bài viết tiếp theo, chúng ta sẽ xem cách chúng ta có thể hiển thị các tệp PDF từ cơ sở dữ liệu MySQL bằng PHP. Tệp PDF sẽ chỉ hiển thị khi nhấp vào một bản ghi cụ thể

Làm cách nào để tải lên PDF trong cơ sở dữ liệu bằng nút js?

Nút. js Tải tệp lên .
Bước 1. Tạo biểu mẫu tải lên. Tạo một nút. js viết biểu mẫu HTML, với trường tải lên. .
Bước 2. Phân tích tệp đã tải lên. Bao gồm mô-đun Formidable để có thể phân tích cú pháp tệp đã tải lên sau khi tệp đến máy chủ. .
Bước 3. Lưu các tập tin

Làm cách nào để lưu trữ tệp PDF trong cơ sở dữ liệu MySQL?

MySQL có kiểu dữ liệu BLOB có thể được sử dụng để lưu trữ các tệp như. pdf,. jpg,. txt và những thứ tương tự. .
'Tôi'. nhập số nguyên
'Tên dự án'. gõ VĂN BẢN
'pdf_doc'. gõ BLOB

Làm cách nào để lưu trữ tệp trong cơ sở dữ liệu MySQL bằng Node js?

Hướng dẫn API REST tải lên tệp MySQL của Node Js .
Bước 1 – Tạo ứng dụng Node Express js
Bước 2 – Cài đặt Express + Mysql + Body parser + cors và Multer Library
Bước 3 – Tạo cơ sở dữ liệu và kết nối ứng dụng với DB
Bước 3 – Tạo máy chủ. tập tin js
Bước 4 – Khởi động máy chủ ứng dụng Node Express Js
Bước 5 – Tải tệp lên bằng ứng dụng Rest Api

Làm cách nào để tải tệp lên MySQL bằng Node js?

Tải lên/lưu trữ hình ảnh trong MySQL bằng Node. .
Nút. js tải lên/lưu trữ hình ảnh trong tổng quan về MySQL
Thiết lập nút. mô-đun js
Định cấu hình cơ sở dữ liệu MySQL & Sequelize
Khởi tạo phần tiếp theo
Xác định mô hình tuần tự hóa
Tạo phần mềm trung gian để tải lên và lưu trữ hình ảnh
Tạo Trình điều khiển để tải lên Hình ảnh

Chúng tôi sẽ tải nhiều bản ghi lên cơ sở dữ liệu và hiển thị tất cả các bản ghi từ cơ sở dữ liệu trên cùng một trang.  

Trong bài viết này, chúng ta sẽ xem cách tải tệp PDF lên cơ sở dữ liệu MySQL bằng PHP.  

Tiếp cận. Đảm bảo bạn đã cài đặt XAMPP hoặc WAMP trên máy của mình. Trong hướng dẫn này, chúng tôi sẽ sử dụng máy chủ WAMP

Tạo cơ sở dữ liệu và bảng

Đầu tiên, chúng ta sẽ tạo một cơ sở dữ liệu có tên là 'geeksforgeeks'. Bạn có thể sử dụng cơ sở dữ liệu hiện có của mình hoặc tạo một cơ sở dữ liệu mới. Tạo bảng có tên ‘pdf_data‘ có 3 cột để lưu dữ liệu. Tham khảo ảnh chụp màn hình sau để biết cấu trúc bảng

cấu trúc bảng

Sao chép và dán đoạn mã sau vào bảng SQL của PHPMyAdmin của bạn

CREATE TABLE IF NOT EXISTS `pdf_data` (
  `id` int(50) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `filename` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Chúng tôi sẽ sử dụng Bootstrap để sử dụng Hệ thống lưới đáp ứng của Bootstrap. Dưới đây là mã để bao gồm liên kết Bootstrap CDN trong phần đầu của mã HTML

  • dbcon. php. Mã này minh họa để kết nối ứng dụng của chúng tôi với cơ sở dữ liệu

PHP




    $host ='localhost';

    

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
1 =
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
3;

    

$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
6 =
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
8;

    

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
1 =
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
3;

 

    5_______6

while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
7$host___
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
9_______1_______1
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
9
$selectQuery = "select * from pdf_data"; 
$squery = mysqli_query($con, $selectQuery);
6
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
9
while (($result = mysqli_fetch_assoc($squery)))
{
    ...
}
1