initial commit
This commit is contained in:
10
demo/php/.htaccess
Normal file
10
demo/php/.htaccess
Normal file
@ -0,0 +1,10 @@
|
||||
RewriteEngine on
|
||||
|
||||
# (as suggested by www.zeilenwechsel.de)
|
||||
|
||||
RewriteBase /
|
||||
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond $1#%{REQUEST_URI} ([^#]*)#(.*)\1$
|
||||
RewriteRule ^(.*)$ %2index.php/$1 [QSA,L]
|
||||
|
7
demo/php/include/config.inc.php
Normal file
7
demo/php/include/config.inc.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
$waveform = array(
|
||||
'snddir' => dirname(__FILE__).'/../../snd',
|
||||
'cachedir' => dirname(__FILE__).'/../../tmp'
|
||||
);
|
||||
|
18
demo/php/include/functions.inc.php
Normal file
18
demo/php/include/functions.inc.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
function fatal_error($msg, $status = '505 Internal Server Error') {
|
||||
header('Status: '.$status);
|
||||
|
||||
echo $msg."\n";
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
function sanitize_path_request($path_info) {
|
||||
return preg_replace(
|
||||
array('|^/|', '/[^A-Za-z0-9\-\.]/'),
|
||||
array('', ''),
|
||||
$path_info
|
||||
);
|
||||
}
|
||||
|
5
demo/php/include/init.inc.php
Normal file
5
demo/php/include/init.inc.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
require_once('config.inc.php');
|
||||
require_once('functions.inc.php');
|
||||
|
32
demo/php/index.php
Normal file
32
demo/php/index.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
set_include_path(dirname(__FILE__).'/include');
|
||||
|
||||
require_once('init.inc.php');
|
||||
|
||||
$path = sanitize_path_request($_SERVER['PATH_INFO']);
|
||||
|
||||
$cachefile = $waveform['cachedir'].'/'.sha1($path);
|
||||
|
||||
$mp3file = $waveform['snddir'].'/'.$path;
|
||||
|
||||
if(!is_file($mp3file))
|
||||
exit(fatal_error("Error: requested file $mp3file not found"));
|
||||
|
||||
if(!file_exists($cachefile)) {
|
||||
$cmdline = 'waveform draw "'.$mp3file.'" "'.$cachefile.'" 0 -1';
|
||||
$system_rv = null;
|
||||
|
||||
system($cmdline, $system_rv);
|
||||
|
||||
if($system_rv!=0) {
|
||||
if(file_Exists($cachefile))
|
||||
unlink($cachefile);
|
||||
|
||||
exit(fatal_error('Error: generating the waveform diagram failed'));
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-type: image/jpeg');
|
||||
|
||||
echo file_get_contents($cachefile);
|
||||
|
Reference in New Issue
Block a user