-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload-test.php
More file actions
66 lines (53 loc) · 1.6 KB
/
upload-test.php
File metadata and controls
66 lines (53 loc) · 1.6 KB
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
66
<?php
include 'config.php';
$collection = $db->song;
// echo "Collection selected succsessfully";
$song=time() . '.' . pathinfo($_FILES['song']['name'], PATHINFO_EXTENSION);
$song_data=upload($song);
if($song_data==1){
$document = array(
"name" => $_POST['name'],
"album" => $_POST['album'],
"singer" => $_POST['singer'],
"song" => $song
);
$result = $collection->insertOne($document);
if(isset($result)){
echo "Document inserted successfully";
}
}
elseif($song_data==2){ echo "upload error" ;}
function upload($file)
{
if (!empty($file)) {
$target_dir = 'music_target/';
$thumb_dir = 'music/';
if (file_exists($target_dir)) {
$target_dir = 'music_target/';
$thumb_dir = 'music/';
} else {
mkdir($target_dir, 0777, true);
mkdir($thumb_dir, 0777, true);
}
$target_file = $target_dir . $file;
$FileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
if ($FileType == 'mp3' || $FileType == 'm4a' || $FileType == 'wav') {
$upload = 0;
// $url = $thumb_dir . $file;
if (move_uploaded_file($_FILES["song"]["tmp_name"], $target_file)) {
//unlink($target_file);
//unlink('users_thumbs/' . $old_file);
// uploaded
return 1;
} else {
//could no upload
return 2;
}
}
else {
//Incompatible format error
return 3 ;
}
}
}
?>