Icontem

File: upload.php

Recommend this page to a friend!
  Classes of Subin Siby  >  Francium JavaScript Voice Recorder  >  upload.php  >  Download  
File: upload.php
Role: Auxiliary data
Content type: text/plain
Description: Upload Audio Example
Class: Francium JavaScript Voice Recorder
Record user voice and encode it as MP3 or WAV
Author: By
Last change: Version 0.4
Date: 3 years ago
Size: 653 bytes
 

Contents

Class file image Download
<?php
/**
 * Request has Base64 Data
 * -----------------------
 * $_POST['audio'] is the Base64 encoded value of audio (WAV/MP3)
 */
if(isset($_POST['audio'])){
  $audio = base64_decode($_POST['audio']);
  
  echo $audio;
}

/**
 * Request has BLOB Data
 * ---------------------
 */
if(isset($_FILES['file'])){
  $audio = file_get_contents($_FILES['file']['tmp_name']);
  
  require_once __DIR__ . "/db.php";
  $sql = $dbh->prepare("INSERT INTO `uploads` (`audio`) VALUES(?)");
  $sql->execute(array($audio));
  
  $sql = $dbh->query("SELECT `id` FROM `uploads` ORDER BY `id` DESC LIMIT 1");
  $id = $sql->fetchColumn();
  
  echo "play.php?id=$id";
}