├── #user.php
├── config.php
├── archive
└── index.html
├── upload
└── index.html
├── logout.php
├── #auth.php
├── functions.php
├── README
├── upload.php
├── index.php
├── split.php
├── setup.php
└── mp3lib.php
/#user.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/config.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/archive/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/upload/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/logout.php:
--------------------------------------------------------------------------------
1 |
2 | session_start();
3 | $_SESSION['auth'] = 0;
4 | header("Location: ./index.php");
5 | ?>
--------------------------------------------------------------------------------
/#auth.php:
--------------------------------------------------------------------------------
1 |
2 | session_start();
3 | if($_SESSION['auth'] != 1)
4 | {
5 | header("Location: ./index.php");
6 | die();
7 | }
8 | ?>
--------------------------------------------------------------------------------
/functions.php:
--------------------------------------------------------------------------------
1 |
2 | //functions
3 | //decode Userdata
4 | function decodeuserdata($string)
5 | {
6 | $string = strrev($string);
7 | $string = base64_decode($string);
8 | return($string);
9 | }
10 | ?>
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | PHP-HTTP-Audiofile-streamer is a PHP based HTTP-Streaming server for MP3 files.
2 | HTTP-Streams are working with MacOS 10.6, iOS 3.x, 4.x. VLC Player support the basics. Flash Player 10.1 also support HTTP-Streaming.
3 | PHP-HTTP-Audiofile-streamer only support Streaming a ready MP3-File (no live streaming).
4 |
5 | This Software is LGPL: http://www.gnu.org/licenses/lgpl.html
6 |
7 | Install:
8 | This is not ready for productive use! Only test and development Version!
9 |
10 | 1. Copy files to an Folder on your PHP-Server.
11 | 2. Give write Access to #user.php, config.php and the dirs upload and archive
12 | 4. open the dir in your browser and configure the setup
13 |
14 | 3. -upload an MP3-File on upload.php
15 | -hope everything works
16 | -get streamURL and try
--------------------------------------------------------------------------------
/upload.php:
--------------------------------------------------------------------------------
1 |
2 | include("#auth.php");
3 | include("./config.php");
4 | ?>
5 |
6 |
7 |
8 |
40 |
41 | Upload to HTTP-Stream
42 |
43 |
44 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 |
2 | include_once('functions.php');
3 | $username = $_POST['username'];
4 | $password = $_POST['password'];
5 |
6 | //check for #user file. no userfile = redirect to setup
7 | if (filesize("#user.php")<1)
8 | {
9 | header("Location: ./setup.php");
10 | die();
11 | }
12 |
13 | //authorise and set session and redirect
14 | if (($username)&&($password))
15 | {
16 | include("#user.php");
17 | //decode password
18 | $rightusername = decodeuserdata($rightusername);
19 | $rightpassword = decodeuserdata($rightpassword);
20 |
21 | if(($username==$rightusername)&&($password==$rightpassword))
22 | {
23 | session_start();
24 | $_SESSION['auth'] = 1;
25 | header("Location: ./upload.php");
26 | die();
27 | }
28 | }
29 |
30 | //check session and redirect
31 | session_start();
32 | if($_SESSION['auth'] == 1)
33 | {
34 | header("Location: ./upload.php");
35 | die();
36 | }
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | ?>
47 |
48 |
49 |
81 |
82 | Upload to HTTP-Stream - Login
83 |
84 |
85 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/split.php:
--------------------------------------------------------------------------------
1 |
2 | error_reporting(1);
3 | include("#auth.php");
4 | include("./mp3lib.php");
5 | include("./config.php");
6 |
7 |
8 |
9 |
10 | $partlenght = $_POST['partlenght'];
11 | if (!$partlenght) $partlenght = 10;
12 |
13 | $filename = $_POST['filename'];
14 | //filename whitespace fix
15 | $filename = str_replace(" ","-",$filename);
16 |
17 |
18 | //check for files / dirs with same name
19 | if (dir($archive_path."/".date("Y-m-d-H-i").$filename))
20 | {
21 | //if same named file / dir exists create new name with counting up the name in (1)
22 | $filenamecounter = 2;
23 | while (dir($archive_path."/".date("Y-m-d-H-i").$filename."(".$filenamecounter.")"))
24 | {
25 | $filenamecounter++;
26 | }
27 | //count ready
28 | $current_file_dir = date("Y-m-d-H-i").$filename."(".$filenamecounter.")";
29 | }
30 | //name is right
31 | else $current_file_dir = date("Y-m-d-H-i").$filename;
32 |
33 | //create dir in archive for saving parts
34 | mkdir($archive_path."/".$current_file_dir);
35 |
36 |
37 |
38 | //test move uploadet file and move it
39 | if(move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir."/".$current_file_dir.".mp3")) {
40 | //
41 | } else{
42 | //error
43 | echo "There was an error uploading the file, please try again!
";
44 | //remove dir becouse it isn't needed anymore (becouse is no content if upload failed)
45 | rmdir($archive_path."/".$current_file_dir);
46 |
47 | //echo Upload Error
48 | if(!$_FILES['file'])
49 | {
50 | $upload_error = "No file was uploaded.";
51 | }
52 | else
53 | {
54 | switch($_FILES['file']['error'])
55 | {
56 | case 0: $upload_error = "here is no error, the file uploaded with success.";
57 | case 1: $upload_error = "The uploaded file exceeds the upload_max_filesize directive in php.ini.";
58 | case 2: $upload_error = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
59 | case 3: $upload_error = "The uploaded file was only partially uploaded.";
60 | case 4: $upload_error = "No file was uploaded.";
61 | case 5: $upload_error = "-";
62 | case 6: $upload_error = "Missing a temporary folder.";
63 | case 7: $upload_error = "Failed to write file to disk.";
64 | case 8: $upload_error = "A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help.";
65 | default: $upload_error = "unknown upload error";
66 | }
67 | }
68 | echo("Upload Error: ".$upload_error."
");
69 | //die
70 | die();
71 | }
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | //get path for original mp3file
82 | $path = $upload_dir.'/'.$current_file_dir.".mp3";
83 | //read MP3
84 | $mp3 = new mp3($path);
85 |
86 |
87 |
88 | //create m3u8 header
89 | $m3u8_file = "#EXTM3U
90 | #EXT-X-MEDIA-SEQUENCE:0
91 | #EXT-X-TARGETDURATION:".$partlenght."
92 | ";
93 |
94 |
95 |
96 |
97 | //start on second 0
98 | $position = 0;
99 | //continue the loop while $continue_mp3split_loop = 1
100 | $continue_mp3split_loop = 1;
101 | while($continue_mp3split_loop==1)
102 | {
103 |
104 | //split the part
105 | $mp3_1 = $mp3->extract($position,$partlenght);
106 | //export and save the part as file
107 | $mp3_1->save($archive_path."/".$current_file_dir.'/'.'file'.$position.'.mp3');
108 |
109 |
110 |
111 | //check if title has ended
112 | if (filesize($archive_path."/".$current_file_dir.'/'.'file'.$position.'.mp3')<2)
113 | {
114 | //stop the loop
115 | $continue_mp3split_loop = 0;
116 | //delete last empty file
117 | unlink($archive_path."/".$current_file_dir.'/'.'file'.$position.'.mp3');
118 | }
119 |
120 | //file is OK
121 | else {
122 | //write file URL to m3u8-index
123 | $m3u8_file = $m3u8_file."#EXTINF:".$partlenght.",
124 | ".$extern_archive_path."/".$current_file_dir.'/'.'file'.$position.'.mp3
125 | ';}
126 |
127 | //count up the secondcounter for next part
128 | $position = $position + $partlenght;
129 | }
130 |
131 |
132 | //finish m3u8-index-file
133 | $m3u8_file = $m3u8_file."#EXT-X-ENDLIST";
134 |
135 | //write m3u8-index-file
136 | $dz = fopen($archive_path."/".$current_file_dir.'/'.'index.m3u8',w);
137 | fwrite($dz,$m3u8_file);
138 | fclose($dz);
139 |
140 | //write empty index.html file
141 | $dz = fopen($archive_path."/".$current_file_dir.'/'.'index.html',w);
142 | fwrite($dz,'');
143 | fclose($dz);
144 |
145 | //echo / save stream index URL
146 | $streanurlcontent = "Upload completet: Stream URL
";
149 | //delete original MP3-file
150 | unlink($upload_dir."/".$current_file_dir.".mp3");
151 |
152 | ?>
153 |
154 |
155 |
187 |
188 | HTTP-Stream - URL
189 |
190 |
191 |
192 |
=$streanurlcontent;?>
193 |
194 |
195 |
196 |
197 |
--------------------------------------------------------------------------------
/setup.php:
--------------------------------------------------------------------------------
1 |
2 | include_once('functions.php');
3 | //check for #user file. no userfile = Setup
4 | if (filesize("#user.php")>1)
5 | {
6 | include("#auth.php");
7 | }
8 |
9 |
10 | include("./config.php");
11 | include("./#user.php");
12 |
13 |
14 |
15 |
16 |
17 | if ($_POST['Button_save'] == "Save")
18 | {
19 | $save = new SaveConfig;
20 | $save->srightusername=$_POST['newusername'];
21 | $save->srightpassword=$_POST['newpassword'];
22 | $save->srightpassword2=$_POST['newpassword2'];
23 | $save->sexternarchivepath=$_POST['externarchivepath'];
24 | $save->sarchive_path=$_POST['archivepath'];
25 | $save->supload_dir=$_POST['uploadpath'];
26 | $save->sdefault_mp3_part_length=$_POST['defaultlength'];
27 |
28 | $save->save();
29 |
30 |
31 | }
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | include("./config.php");
42 |
43 |
44 | //fill in existing Userdata
45 | if (filesize("./#user.php")>1)
46 | {
47 | include("./#user.php");
48 | $rightusername = decodeuserdata($rightusername);
49 | $externarchivepath = $extern_archive_path;
50 | $archive_path = $archive_path;
51 | $upload_dir = $upload_dir;
52 | $default_mp3_part_length = $default_mp3_part_length;
53 | }
54 | //OR generate new Settings on new installation OR Passwordreset
55 | else
56 | {
57 | $currentpath = 'http://' . $_SERVER['HTTP_HOST'] . str_replace("setup.php","",$_SERVER['SCRIPT_NAME']);
58 | $externarchivepath = $currentpath."archive";
59 |
60 | $archive_path = "archive";
61 | $upload_dir = "upload";
62 | $default_mp3_part_length = "10";
63 | }
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 | class SaveConfig
79 | {
80 | public $srightusername;
81 | public $srightpassword;
82 | public $srightpassword2;
83 | public $sexternarchivepath;
84 | public $sarchive_path;
85 | public $supload_dir;
86 | public $sdefault_mp3_part_length;
87 |
88 | private $errormessage;
89 | private $successmessage;
90 |
91 | function checkUserChanges()
92 | {
93 | //Username and both passwords are given
94 | if(($this->srightusername)&&($this->srightpassword)&&($this->srightpassword2))
95 | {
96 | //Passwords are not identic
97 | if (($this->srightpassword)!=($this->srightpassword2))
98 | {
99 | $this->addErrorMessage("Passwords not identical");
100 | return false;
101 | }
102 | //Username given, both passwords didentic -> all right
103 | else
104 | {
105 | return true;
106 | }
107 | }
108 | //Passwords given but no username
109 | elseif ($this->srightusername == "")
110 | {
111 | $this->addErrorMessage("No Username");
112 | return false;
113 | }
114 | //don't use Data to save
115 | else
116 | {
117 | return false;
118 | }
119 |
120 |
121 | }
122 |
123 | //Save User Chaneges as fliped Base64 in #user.php
124 | function saveUserChanges()
125 | {
126 |
127 | //decode
128 | $this->usernameToSave = $this->encodeUserData($this->srightusername);
129 | $this->passwordToSave = $this->encodeUserData($this->srightpassword);
130 |
131 | $data_to_write = "
132 | \$rightusername = \"".$this->usernameToSave."\";
133 | \$rightpassword = \"".$this->passwordToSave."\";
134 | ?>";
135 | //write file
136 | $dz = fopen('#user.php',w);
137 | fwrite($dz,$data_to_write);
138 | fclose($dz);
139 |
140 | }
141 |
142 | //encode user data (fliped Base64)
143 | function encodeUserData($string)
144 | {
145 | $string = base64_encode($string);
146 | $string = strrev($string);
147 | return($string);
148 | }
149 |
150 | function addErrorMessage($message)
151 | {
152 | $this->errormessage = $this->errormessage."".$message."";
153 | }
154 |
155 | function returnErrorMessage()
156 | {
157 | if($this->errormessage)
158 | {
159 | return "Error
";
160 | }
161 | }
162 |
163 | function addSuccessMessage($message)
164 | {
165 | $this->successmessage = $this->successmessage."".$message."";
166 | }
167 |
168 | function returnSuccessMessage()
169 | {
170 | if($this->successmessage)
171 | {
172 | return "Success
".$this->successmessage."
";
173 | }
174 | }
175 |
176 |
177 |
178 | //checks settings configuration
179 | function checkConfig()
180 | {
181 | $this->checkDir($this->sarchive_path);
182 | $this->checkDir($this->supload_dir);
183 | //Check MP3 lenth is set
184 | if(round($this->sdefault_mp3_part_length==0))
185 | {
186 | $this->addErrorMessage("MP3 lenth is not a Number");
187 | }
188 | elseif(!$this->sexternarchivepath)
189 | {
190 | $this->addErrorMessage("Extern Archive URL not set");
191 | }
192 | else
193 | {
194 | return true;
195 | }
196 |
197 | }
198 |
199 | //checks directorys for write access and existence
200 | function checkDir($dir)
201 | {
202 | if (is_writeable($dir))
203 | {
204 | return(true);
205 | }
206 | else
207 | {
208 | $this->addErrorMessage("no write Access to Dir: ".$dir);
209 | return(false);
210 | }
211 | }
212 |
213 | function save()
214 | {
215 | if ($this->checkUserChanges())
216 | {
217 | //check for write access for #user.php
218 | if(is_writeable('#user.php'))
219 | {
220 | $this->SaveUserChanges();
221 | $this->addSuccessMessage("Userdata Saved");
222 | }
223 | else
224 | {
225 | $this->addErrorMessage("no write Access to #user.php");
226 | }
227 | }
228 |
229 | //Ceck Config Save
230 | if ($this->checkConfig())
231 | {
232 | if(is_writeable('config.php'))
233 | {
234 | $this->SaveServerChanges();
235 | $this->addSuccessMessage("Config Saved");
236 | }
237 | else
238 | {
239 | $this->addErrorMessage("no write Access to config.php");
240 | }
241 | }
242 | }
243 |
244 | //save Configdata
245 | function SaveServerChanges()
246 | {
247 | $data_to_write = "
248 | /*CONFIG FILE*/
249 | /*SERVER CONFIG*/
250 | \$archive_path = \"".$this->sarchive_path."\"; //Path to Archive Dir
251 | \$extern_archive_path = \"".$this->sexternarchivepath."\";
252 | \$upload_dir = \"".$this->supload_dir."\";
253 | /*MP3 SPLIT OPTIONS*/
254 | \$default_mp3_part_length = \"".round($this->sdefault_mp3_part_length)."\"; //default length of MP3 parts in seconds
255 | ?>";
256 | //write file
257 | $dz = fopen('config.php',w);
258 | fwrite($dz,$data_to_write);
259 | fclose($dz);
260 | }
261 |
262 | }
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 | ?>
290 |
291 |
292 |
293 |
344 |
345 | Setup HTTP-Stream
346 |
347 |
348 |
349 | if ($save)
350 | {
351 | if($save->returnErrorMessage())
352 | {
353 | echo "".$save->returnErrorMessage()."
";
354 | }
355 |
356 | if($save->returnSuccessMessage())
357 | {
358 | echo "".$save->returnSuccessMessage()."
back ";
359 | die("");
360 | }
361 | }
362 | ?>
363 |
392 |