-
Notifications
You must be signed in to change notification settings - Fork 3
/
save.php
executable file
·63 lines (57 loc) · 1.99 KB
/
save.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
session_start();
require_once('./sys/config.php');
require_once("./controllers/traces.handler.class.php");
function audio_convert($file, $filename){
$commandeConv = str_replace(array("%source%", "%target%"), array("./enregistrements/".$filename.".ogg","./enregistrements/".$filename.".mp3"), $file);
return $commandeConv;
}
$fileName = '';
$ext = ".ogg";
foreach(array('audio') as $type) {
if (isset($_FILES["audio-blob"])) {
$fileName = $_POST["audio-filename"];
$_SESSION['filename']=$fileName;
$uploadDirectory = './enregistrements/'.$fileName;
if (!move_uploaded_file($_FILES["audio-blob"]["tmp_name"], $uploadDirectory)) {
throw new Exception('problem moving uploaded file');
}
}
// récupère dans un tableau de hachage le nom du fichier sans l'extension, l'extension et le chemin
$file = pathinfo('./enregistrements/'.$fileName);
// convertit en mp3
if($conversion!==false){
//#format
if($conversion=="mp3"){
$conversion = "avconv -i %source% -acodec libmp3lame -q:a 2 -ac 1 %target%";
}
$commande = audio_convert($conversion, $file['filename']);
exec($commande);
// Supression du fichier.wav du serveur.
exec("rm ./enregistrements/".$file['filename'].".ogg");
$ext = ".mp3";
}
// ajout 15/02
//$_SESSION['userid']=$userid;
//enregistrement dans la BD de la partie de l'oracle
if($fileName!='')
//$userid = $_POST["filename"];
//$_SESSION['userid']=$userid;
{
$fileName=$file['filename'].$ext;
//renomme le nom du fichier à rentrer dans la BD
$duration = 1;//durée minimale…
if($ext == ".mp3"){
//would better use ffmpeg, but if we do that, might as well replace avconv
//see http://stackoverflow.com/questions/12053125/php-function-to-get-mp3-duration#answer-15237692
//short term solution
require_once("./sys/mp3.utils.php");
$mp3_file = new MP3File("./enregistrements/$fileName");
$duration = $mp3_file->getDuration();
}
$th = new TracesHandler();
$th->post_record($_GET["cardid"], $fileName, $duration);
echo $fileName;
}
}
?>