Integration Testing Company India
Blazingcoders in India has a dedicated team of testers to perform Integration testing. Integration testing is the phase in software testing in which individual software modules are combined and tested
Read More
How to Record Audio and Upload to Folder in Codeigniter
Today we are going to explain how to record manually and upload it to a folder then insert that audio file into the Database using the Codeigniter PHP framework. In this, you can easily record audio and upload it to the destination folder.
Record Audio using Codeigniter
Here are the steps to record audio and upload it to a folder using Codeigniter.
STEP 1 :
STEP 2:
audio.php file (Views)
<body>
<article>
<section class="experiment recordrtc">
<h2 class="header">
<select style="display:none;" class="recording-media">
<option value="record-video">Video</option>
<option selected value="record-audio">Audio</option>
<option value="record-screen">Screen</option>
</select>
<select style="display:none;" class="media-container-format">
<option>WebM</option</
</select>
<button style="text-align:center;">Start Recording</button>
</h2>
<div style="display: none;">
<button id="save-to-disk" style="display: none;">Save To Disk</button>
<button id="open-new-tab" style="display: none;">Open New Tab</button>
<button id="upload-to-server">Upload To Server</button>
</div>
</section>
</body>
STEP 3 :
Audio.php file (Controller)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Audio extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
*- or -
* http://example.com/index.php/welcome/index
*- or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
/*-------------- View-------------------*/
public function index()
{
$this->load->view('audio');
}
public function audio_record(){
if (!isset($_POST['audio-filename']) && !isset($_POST['video-filename'])) {
echo 'Empty file name.';
return;
}else{
if (false && isset($_POST['audio-filename']) &&
strrpos($_POST['audio- filename'], "RecordRTC-") !== 0) {
echo 'File name must start with "RecordRTC-"';
return;
}
}
$fileName = $tempName = $file_idx = '';
if (!empty($_FILES['audio-blob'])) {
$file_idx = 'audio-blob';
$fileName = $_POST['audio-filename'];
$tempName = $_FILES[$file_idx]['tmp_name'];
} else {
$file_idx = 'video-blob';
$fileName = $_POST['video-filename'];
$tempName = $_FILES[$file_idx]['tmp_name'];
}
if (empty($fileName) || empty($tempName)) {
if(empty($tempName)) {
echo 'Invalid temp_name: '.$tempName;
return;
}
echo 'Invalid file name: '.$fileName;
return;
}
$filePath = 'uploads/' . $fileName;
$allowed = array('webm', 'wav', 'mp4', 'mkv','mp3', 'ogg' );
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
if (!$extension || empty($extension) || !in_array($extension, $allowed)) {
echo 'Invalid file extension: '.$extension;
return;
}
if (!move_uploaded_file($tempName, $filePath)) {
if(!empty($_FILES["file"]["error"])) {
echo 'Not uploaded because of error #'.$_FILES["file"]["error"];
}
else {
echo 'Problem saving file: '.$tempName;
}
return;
}else {
$data['file'] = $fileName;
$this->load->model('Home_model');
$status=$this->Home_model->insert_audio($data);
}
} }
?>
STEP 4:
Audio (Database)
STEP 5:
Home_model.php file (Models)
<?php
class Home_model extends CI_Model
{
public function insert_audio($data){
return $this->db->insert('files',$data);
}
}
?>
STEP 6:
Request a FREE Business Plan.
+91 ▼ Blazingcoders in India has a dedicated team of testers to perform Integration testing. Integration testing is the phase in software testing in which individual software modules are combined and tested
Read MoreOffshore and Outsource jQuery Developers: Transform Your Front-End Development A website that is both interesting and easy to use is essential for success in the digital-first world of today. A cro
Read MoreIn the digital age, businesses and individuals are constantly searching for ways to enhance their online presence. This has led to the rise of web development and web application development as two co
Read More