-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread-file.php
63 lines (58 loc) · 2.26 KB
/
read-file.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
<?php
use MagicObject\Request\InputGet;
use MusicProductionManager\Constants\HttpHeaderConstant;
use MusicProductionManager\Data\Entity\Album;
use MusicProductionManager\Data\Entity\EntitySong;
use MusicProductionManager\Data\Entity\EntitySongDraft;
use MusicProductionManager\Utility\FileUtil;
require_once "inc/auth-with-login-form.php";
$inputGet = new InputGet();
if ($inputGet->getType() == "draft") {
try {
$songDraft = new EntitySongDraft(null, $database);
$songDraft->findOneBySongDraftId($inputGet->getSongDraftId());
$filename = $songDraft->getSongDraftId() . ".mp3";
header(HttpHeaderConstant::CONTENT_TYPE . "audio/mp3");
header(HttpHeaderConstant::CONTENT_DISPOSITION . "attachment; filename=\"$filename\"");
header(HttpHeaderConstant::CONTENT_LENGTH . filesize($songDraft->getFilePath()));
readfile($songDraft->getFilePath());
} catch (Exception $e) {
// do nothing
echo $e->getMessage();
}
exit();
} else if ($inputGet->getSongId() != null) {
try {
$song = new EntitySong(null, $database);
$song->findOneBySongId($inputGet->getSongId());
FileUtil::downloadPerSong($inputGet, $song);
} catch (Exception $e) {
// do nothing
echo $e->getMessage();
}
exit();
} else if ($inputGet->getAlbumId() != null) {
$tempDir = FileUtil::prepareTempDir(__DIR__);
try {
FileUtil::compressOutput(false);
$songs = new EntitySong(null, $database);
$result = $songs->findByAlbumId($inputGet->getAlbumId());
$album = new Album(null, $database);
$album->findOneByAlbumId($inputGet->getAlbumId());
$path = tempnam($tempDir, "tmp_");
$zip = new ZipArchive();
foreach ($result->getResult() as $song) {
FileUtil::downloadSongFiles($zip, $path, $song, true);
}
$zip->close();
$filename = $album->getName() . ".zip";
header(HttpHeaderConstant::CONTENT_DISPOSITION . "attachment; filename=\"$filename\"");
header(HttpHeaderConstant::CONTENT_TYPE . "application/zip");
header(HttpHeaderConstant::CONTENT_LENGTH . filesize($path));
readfile($path);
unlink($path);
} catch (Exception $e) {
// do nothing
}
exit();
}