-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.php
65 lines (55 loc) · 1.93 KB
/
admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require 'admin-DB-connection.php';
$ptitle = $_POST['ptitle'];
$description = $_POST['description'];
$file_1 = $_FILES['thumbnail']['name'];
// $file_2 = $_FILES['file']['name'];
$file = '';
$file_tmp = '';
$location = "../.././Upload/";
$data = '';
foreach ($_FILES['media2']['name'] as $key => $val) {
$file = $_FILES['media2']['name'][$key];
$file_tmp = $_FILES['media2']['tmp_name'][$key];
move_uploaded_file($file_tmp, $location . $file);
$data .= $file . " ";
}
// know the file type
$type = pathinfo($file_1 . $file_2, PATHINFO_EXTENSION);
if ($type == "jpeg" || $type == "jpg" || $type == "png" || $type == "mp4" || $type == "mkv") {
// to place the pictures on server
move_uploaded_file($_FILES['thumbnail']['tmp_name'], '../.././Upload/' . $file_1);
// move_uploaded_file($_FILES['file']['tmp_name'], '../.././Upload/'.$file_2);
$sql = "insert into admin(ptitle,description,media,file,media2) values('$ptitle','$description','$file_1','$file_2','$data')";
$x = mysqli_query($conn, $sql);
if ($x == 1) {
header("location:upload-successful.php?msg=Done");
} else {
header("location:upload-page.php?msg=NotDone");
}
} else {
header("location:upload-page.php?msg=type-not-matched");
}
?>
Multiple picture add logic
<?php
// // Count total uploaded files
// $totalfiles = count($_FILES['file']['name']);
// // Looping over all files
// for($i=0;$i<$totalfiles;$i++){
// $filename = $_FILES['file']['name'][$i];
// // Upload files and store in database
// if(move_uploaded_file($_FILES["file"]["tmp_name"][$i],'../.././Upload/'.$filename)){
// // Image db insert sql
// $insert = "INSERT into admin(file) values('$filename')";
// if(mysqli_query($conn, $insert)){
// echo 'Data inserted successfully';
// }
// else{
// echo 'Error: '.mysqli_error($conn);
// }
// }else{
// echo 'Error in uploading file - '.$_FILES['file']['name'][$i].'<br/>';
// }
// }
?>