Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7160149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:21:04+00:00 2026-05-28T13:21:04+00:00

I am using codeigniter and Jquery. I have an upload form in my view

  • 0

I am using codeigniter and Jquery. I have an upload form in my view script. The upload form consist of several text inputs and a file input. The form will popped out when someone click on it’s menu link ( I did it with Jquery Modal form). Is it any possible way to simulate an ajax call upon the form submit? so when user click submit, the file would be send to a directory on the server and so the information would be stored in the database.

here’s my code:
THE VIEW:

<div id="right_column" class="grid_7 omega">
        <section id="music_features">
            <header>
                <hgroup>
                    <h1>Your Playlist</h1>
                    <p>Up to only 3 files allowed for beta version</p>
                </hgroup>
            </header>
            <p id="song_upload_menu"><?php echo anchor('#', 'Upload Song');?></p>
            <article id="song_upload_form">
                <div id="song_upload_info">
                    <?php echo $this->session->flashdata('info'); ?>
                </div>
                <?php echo form_open_multipart('profile/do_upload_song');?>
                <input type="hidden" id="user_id" name="user_id" value="<?php echo $user->id_str;?>" />
                <label for="title">Song Title</label>
                <input type="text" name="title" id="title" size="30" value="<?php echo set_value('title'); ?>"/><br />
                <label for="album"> Album Title </label>
                <input type="text" name="album" id="album" size="30" value="<?php echo set_value('album'); ?>"/><br />
                <label for="artist">Artist</label>
                <input type="text" name="artist" id="artist" size="20" value="<?php echo set_value('artist'); ?>"/><br />
                <input type="file" name="userfile" size="20" /><br />
                <input type="radio" name="license" id="license" value="owner"/>I AM the artist/owner of this song and I have the right for distribution<br />
                <input type="radio" name="license" id="license" value="not owner"/>I AM NOT the artist/owner of this song BUT I have the right for distribution</br>
                <input type="checkbox" name="song_license_agreement"/>By selecting this option, I swear that all information entered is right<br />
                <input type="submit" id="song_upload_submit" value="Upload Your Song"/>
                </form>
            </article>
            <ul id="playlist">
                <!-- your song goes here -->
            </ul>
        </section>

THis is a function in my controller to handle te upload :

function do_upload_song()
    {
        //$file_element_name = 'users_song';

        $config['upload_path'] = './media/';
        $config['allowed_types'] = 'mp3';
        $config['max_size'] = '30720';
        $config['encrypt_name'] = TRUE;

        $this->load->library('upload', $config);
        //set validation rules
        $this->form_validation->set_rules('title', 'Song title', 'trim|required|xss_clean');
        $this->form_validation->set_rules('album', 'Album', 'trim|required|xss_clean');
        $this->form_validation->set_rules('artist', 'Artist', 'required|xss_clean');
        $this->form_validation->set_rules('license', 'License', 'required');
        $this->form_validation->set_rules('song_license_agreement', 'License Agreement', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->session->set_flashdata('info', validation_errors());
            redirect('profile');
        }
        else
        {
            if ( ! $this->upload->do_upload())
            {
                $this->session->set_flashdata('info', $this->upload->display_errors());
                redirect('profile');
            }
            else
            {
                $data = $this->upload->data();
                $add_song = $this->media_model->add_song($data['file_name']);
                if($add_song)
                {
                    $this->session->set_flashdata('info', 'Your song has been uploaded');
                    redirect('profile');
                }
                else
                {
                    unlink($data['full_path']);
                    $this->session->set_flashdata('info', 'Song upload fail');
                    redirect('profile');
                }

            }
            @unlink($_FILES);
        }

    }

And this is my .js

$(document).ready(function(){
$('#song_upload_form').hide();
    $('#song_upload_menu').click(function(e){                             
        $('#song_upload_form').dialog({
                        title: 'Upload the cool track man!',
                        width: 520,
                        show: 'fade',
                        hide: 'fade',
                        modal: true
                        });                       
        e.preventDefault();
    });  
});   

The JS script makes the modal form popped out, but i don’t know what to do after that. I just can send the data via ajax. But file is different. I know they cannot be sent via ajax. Many articles I found on the net told me about Iframe, but they only deal with file. I can’t find a practical solution to solve my problem which is simulating ajax to send data and file simultaneously . Any advice guys? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:21:05+00:00Added an answer on May 28, 2026 at 1:21 pm

    I was just reading about this myself. Look here: http://joekuan.wordpress.com/2009/06/12/ajax-a-simplified-version-of-file-upload-form-using-iframe/

    It says you can redirect the form upload to a hidden iframe. Pretty cool. I’ve yet to try it myself, but you should be able to find all sorts of information about it online.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Codeigniter framework and I have a form with input fields. When
I have a form which uploads multiple file fields into a db using codeigniter.
I am using codeigniter framework and in view i am using jquery. Now, I
I have integrate jQuery thick box in Codeigniter, when I am using this thick
I have this form that validates the fields on submit through ajax (using Codeigniter's
I have a search form: <form id=global_search> <input id=global_search_input name=search_query placeholder=Enter search text> <input
I have a PHP project (I'm using CodeIgniter) with data capture. The form is
I am doing a multiple upload using the Multiple_upload library in codeigniter, and form
I'm using codeigniter for this project. I have a search form and search form
I have a codeigniter application.In that i call the controller function using ajax/jquery.But when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.