-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaudio.php
More file actions
executable file
·62 lines (53 loc) · 1.67 KB
/
audio.php
File metadata and controls
executable file
·62 lines (53 loc) · 1.67 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
<?php
header('Content-Type: application/json');
$targetDir = '/usr/share/nginx/html/assets/audio/';
$featuredFile = $targetDir . 'featured.mp3';
// Collect debug info
$debug = [
'php_tmp_dir' => sys_get_temp_dir(),
'target_dir_exists' => is_dir($targetDir),
'target_dir_writable' => is_writable($targetDir),
'files_received' => $_FILES
];
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
$debug['error'] = 'Invalid request method';
echo json_encode($debug);
exit;
}
// Check if file uploaded
if (empty($_FILES['audio']['name'])) {
$debug['error'] = 'No audio file uploaded';
echo json_encode($debug);
exit;
}
// Ensure target directory exists
if (!is_dir($targetDir)) {
if (!mkdir($targetDir, 0775, true)) {
$debug['error'] = 'Failed to create target directory';
echo json_encode($debug);
exit;
}
}
// Ensure directory is writable
if (!is_writable($targetDir)) {
chmod($targetDir, 0775);
$debug['target_dir_writable'] = is_writable($targetDir);
}
// Remove previous featured file
if (file_exists($featuredFile)) {
unlink($featuredFile);
}
// Move uploaded file
$tmpFile = $_FILES['audio']['tmp_name'];
if (is_uploaded_file($tmpFile) && move_uploaded_file($tmpFile, $featuredFile)) {
$debug['status'] = 'success';
$debug['file'] = 'assets/audio/featured.mp3';
} else {
$debug['status'] = 'error';
$debug['error'] = 'Failed to move uploaded file. Check PHP temp dir and folder permissions.';
$debug['tmp_file_exists'] = file_exists($tmpFile);
$debug['tmp_file_path'] = $tmpFile;
$debug['tmp_file_perm'] = is_writable($tmpFile) ? 'writable' : 'not writable';
}
echo json_encode($debug);
exit;