how to optimize OpenCart website ?
Ways to Speed up OpenCart website There are several ways to Optimize OpenCart website that help improve your site's speed and performance. The procedures below show you how to do this so
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 ▼
Ways to Speed up OpenCart website There are several ways to Optimize OpenCart website that help improve your site's speed and performance. The procedures below show you how to do this so
Read More
This article we are going shows how to disable browser cache easily for particular, individual and separate functions and controller in Codeigniter. We face some kind of problems in real life when bro
Read More
In this article, we are going to explain how to make a simple login form with sessions and Login in the Codeigniter framework. In this tutorial, we will make simple login forms with sessions by using
Read More