File tree 3 files changed +48
-0
lines changed
3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ assets
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < title > Upload Multiple Files PHP | Jago Ngoding</ title >
7
+ </ head >
8
+ < body >
9
+ < h1 > Upload Multiple Files PHP | Jago Ngoding</ h1 >
10
+ < form action ="proses.php " method ="POST " enctype ="multipart/form-data ">
11
+ < div >
12
+ < label > Pilih gambar</ label > < br >
13
+ < input type ="file " name ="listGambar[] " accept ="image/* " multiple >
14
+ </ div >
15
+
16
+ < button style ="margin-top: 2rem "> Upload</ button >
17
+ </ form >
18
+ </ body >
19
+ </ html >
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ $ folderUpload = "./assets/uploads " ;
4
+
5
+ # periksa apakah folder tersedia
6
+ if (!is_dir ($ folderUpload )) {
7
+ # jika tidak maka folder harus dibuat terlebih dahulu
8
+ mkdir ($ folderUpload , 0777 , $ rekursif = true );
9
+ }
10
+
11
+ $ files = $ _FILES ;
12
+ $ jumlahFile = count ($ files ['listGambar ' ]['name ' ]);
13
+
14
+ for ($ i = 0 ; $ i < $ jumlahFile ; $ i ++) {
15
+ $ namaFile = $ files ['listGambar ' ]['name ' ][$ i ];
16
+ $ lokasiTmp = $ files ['listGambar ' ]['tmp_name ' ][$ i ];
17
+
18
+ $ namaBaru = uniqid () . '- ' . $ namaFile ;
19
+ $ lokasiBaru = "{$ folderUpload }/ {$ namaBaru }" ;
20
+ $ prosesUpload = move_uploaded_file ($ lokasiTmp , $ lokasiBaru );
21
+
22
+ # jika proses berhasil
23
+ if ($ prosesUpload ) {
24
+ echo "Upload file <a href=' {$ lokasiBaru }' target='_blank'> {$ namaBaru }</a> berhasil. <br> " ;
25
+ } else {
26
+ echo "<span style='color: red'>Upload file {$ namaFile } gagal</span> <br> " ;
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments