Insert mp3 audio
Hello, friends. In this tutorial, I will show you to insert mp3 audio file into the MySQL database and upload the mp3 audio file to a project directory using Codeigniter Framework.
Every web developer knows that file uploads are an essential process in many web application. The most website requires an integrated file upload component. If you need to upload the audio file, so this tutorial will be very helpful for you.
This tutorial discusses step by step process of uploading a file. The important part of this tutorial that you could validate file size and type during the upload process. Follow the steps to work on your project.
Create Folder and Uploading form
First of all, you need to create a directory folder in your project folder, where you store the MP3 Audio File. For example:
Project Folder/assets/audio
After that, create an upload form in the project folder. Go to the view directory and create an audio_form.php file and open it in a text editor for making an uploading form. For making the upload form you can use bootstrap as usual.
Project Folder /application/views/ audio_form.php
Form:
<?php echo form_open_multipart('audio-insertdata','method="post"')?> <div class="item form-group"> <label class="control-label col-md-3 col-sm-3 col-xs-12" for="news_image">Playlist Audio <span class="required">*</span> </label> <div class="col-md-6 col-sm-6 col-xs-12"> <input type="file" id="play_list_audio" name="play_list_audio" required="required" class="form-control col-md-7 col-xs-12"> </div> </div> <div class="ln_solid"></div> <div class="form-group"> <div class="col-md-6 col-md-offset-3"> <button id="send" type="submit" class="btn btn-success">Submit</button> </div> </div> <?php echo form_close(); ?>
Define a route:
<?php $route['audio-insertdata']="Controller/audio_insertdata"; ?>
If you want to use .htaccess to remove index.php, go to the config.php page and remove index.php and create a .htaccess file.
Project Folder/application/config/config.php
Set it: $config[‘index_page’] = ”;
Get .htaccess code here
Create Controller:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Controller extends CI_Controller { public function __construct(){ parent::__construct(); $this->load->helper('url'); $this->load->helper('form'); // Model $this->load->model('Model'); // Session $this->load->library('session'); } // Audio Insert public function audio_insertdata(){ $config['upload_path'] = './assets/audio'; $config['allowed_types'] = 'gif|jpg|png|jpeg|mp3'; $config['max_size'] = 0; $this->load->library('upload', $config); $this->upload->do_upload('play_list_audio'); $up_file = $this->upload->data(); $up_audio=$up_file['file_name']; $data = array("play_list_audio"=>$up_audio); $this->Model->AudioInsertdata($data); } } ?>
Create Model:
Here I have created a table with name audio. In this table, I will store the file name.
<?php class Model extends CI_Model{ function __construct() { parent::__construct(); $this->load->database(); } // Audio File Insert function AudioInsertdata($data){ $ins_qry=$this->db->insert('audio',$data); if($ins_qry){ $this->session->set_flashdata("success","Success! Audio data submit done."); return redirect('add-audio'); }else{ $this->session->set_flashdata("error","Error! Audio data submit faild."); return redirect('add-audio'); } } } ?>
code note work praparly
Show your error please, sorry for delay reply.
Truly when someone doesn’t be aware of then its up
to other visitors that they will help, so here it takes place.
Right away I am going to do my breakfast, once having my breakfast coming yet
again to read further news.
Good day! This is my first visit to your blog! We are a collection of volunteers and starting
a new initiative in a community in the same niche. Your
blog provided us beneficial information to work on. You have done a marvellous
job!
If the player folds, then they shed the ante bet but reduce their potential extra losses suitable there.
Thanks for finally writing about > Insert MP3 Audio file in Codeigniter – Datainflow < Loved it!
If you desire to take a great deal from this article then you have to apply such techniques
to your won weblog.
This was the very first recorded suitable cosmetic breast surgery in history.
Good post. I learn something totally new and challenging
on sites I stumbleupon every day. It will always be useful to read content
from other authors and practice a little something
from their websites.
Hello! Do you use Twitter? I’d like to follow you if that would be okay.
I’m absolutely enjoying your blog and look forward to new updates
Thanks a bunch for sharing this with all folks you really understand what
you are speaking approximately! Bookmarked. Please also visit my
website =). We may have a hyperlink alternate arrangement among us
Pretty nice post. I just stumbled upon your weblog and wished
to say that I have really enjoyed surfing around your blog posts.
In any case I’ll be subscribing to your rss feed and I hope you write again very soon!
I used to be able to find good info from your content.
I just could not depart your web site before suggesting
that I really loved the usual information an individual supply
for your guests? Is gonna be again incessantly in order to investigate cross-check new
posts
Very nice post. I just stumbled upon your weblog and wished to
say that I’ve truly enjoyed browsing your blog posts. In any case I’ll be
subscribing to your rss feed and I hope you write again soon!
Hello outstanding website! Does running a blog like this require a great deal of work?
I’ve no knowledge of computer programming however I
was hoping to start my own blog soon. Anyways, should you have any recommendations or
tips for new blog owners please share. I understand this is off topic but I simply had to ask.
Thanks!
Great delivery. Outstanding arguments. Keep up
the good spirit.
Look at my blog clark county
Hi there every one, here every one is sharing these familiarity,therefore it’s nice to read this webpage, and I used tto visit this website every day.