· 6 years ago · Sep 24, 2019, 01:32 PM
1<?php
2
3error_reporting(E_ALL);
4date_default_timezone_set('Europe/Amsterdam');
5session_start();
6
7/* This script is used to remove music numbers out of my playlist that i don't like */
8
9if (isset($_GET['show'])) {
10 $i = base64_decode($_GET['show']);
11 if (file_exists($i)) {
12 readfile($i);
13 exit;
14 }
15 else {
16 die ("file not exists");
17 }
18}
19
20$startDir = "e:\\Top 40\\2013\\";
21// check if $startDir exists or try to create them.
22if (!is_dir($startDir)) {
23 die("Start directory does not exists");
24}
25
26if (!isset($_SESSION['mp3List'])) {
27 // first create list of mp3s
28 $files = scandir($startDir);
29 if (count($files) > 0) {
30 $_SESSION['mp3List'] = array_diff($files, array('..', '.'));
31
32 if (count($files) < 1) {
33 die("No (more) files found");
34 }
35 }
36 else {
37 die("No files found for reading");
38 }
39}
40
41if (!isset($_SESSION['mp3List']) OR
42 count($_SESSION['mp3List']) < 1) {
43 die("No more music to process, reset session");
44}
45else {
46 $displayMessage = "";
47
48 // get the first mp3 song;
49 $s = array_values($_SESSION['mp3List']);
50 $i = array_shift($s);
51 $image = $i;
52 $mp3Full = $startDir . "\\" . $i;
53
54 if ($_SERVER['REQUEST_METHOD'] == "POST") {
55 switch ($_POST['action']) {
56 case "Reset":
57 // destroy all session
58 session_destroy();
59
60 header("Location: " . basename(__FILE__));
61 exit;
62 break;
63 case "Delete":
64 //
65 if (!unlink($mp3Full)) {
66 die("can\'t delete image");
67 }
68 $_SESSION['mp3List'] = array_shift($_SESSION['mp3List']);
69 header("Location: " . basename(__FILE__));
70 exit;
71 break;
72
73 default:
74 // remove first file from the list
75 $_SESSION['imagesList'] = array_shift($_SESSION['mp3List']);
76 break;
77
78 }
79 }
80}
81
82// display first file from the list
83?>
84<center>
85<form method="post">
86<table>
87<tr>
88<td><input type="submit" name="action" value="Next" accesskey="n" /></td>
89<td><input type="submit" name="action" value="Delete" accesskey="d" /></td>
90<td><input type="submit" name="action" value="Reset" accesskey="r" /></td>
91<td><?php echo count($_SESSION['mp3List']); ?></td>
92</tr>
93</table>
94</form>
95<p><?php echo $mp3Full; ?></p>
96<audio controls autoplay loop id="playAudio">
97 <source src="?show=<?php echo base64_encode($mp3Full); ?>" type="audio/mpeg">
98Your browser does not support the audio element.
99</audio>
100</center>