-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
60 lines (52 loc) · 1.94 KB
/
upload.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
<?php
// Check if a file has been uploaded
if(isset($_FILES['uploaded_file'])) {
// Make sure the file was sent without errors
if($_FILES['uploaded_file']['error'] == 0) {
// Connect to the database
$dbLink = new mysqli('localhost', 'root', 'root', 'waih_dk_db');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
// Gather all required data
$name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
$mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
$data = (file_get_contents($_FILES ['uploaded_file']['tmp_name']));
$description = $_POST['description'];
$show_name = $_POST['show_name'];
$show_host = $_POST['show_host'];
$show_guest = $_POST['show_guest'];
$path = "audio/" . $name ;
file_put_contents($path ,$data);
// Create the SQL query
$query = "
INSERT INTO `Podcasts` (
`name`, `mime`, `description`, `show_name`, `show_host`, `show_guest`, `path`
)
VALUES (
'{$name}', '{$mime}', '{$description}','{$show_name}','{$show_host}', '{$show_guest}', '{$path}'
)";
// Execute the query
$result = $dbLink->query($query);
// Check if it was successfull
if($result) {
echo 'Success! Your file was successfully added!';
}
else {
echo 'Error! Failed to insert the file'
. "<pre>{$dbLink->error}</pre>";
}
}
else {
echo 'An error accured while the file was being uploaded. '
. 'Error code: '. intval($_FILES['uploaded_file']['error']);
}
// Close the mysql connection
$dbLink->close();
}
else {
echo 'Error! A file was not sent!';
}
// Echo a link back to the main page
echo '<p>Click <a href="index1.php">here</a> to go back</p>';
?>