Codeigniter Ajax File Upload
Codeignier Ajax File Upload module is easy and simple and build with Codeigniter File Uplaod Library and AjaxFileUpload – Jquery Plugin .
File: ajaxupload.php (Contorller).
function doupload(){
$uploadFile = uri_assoc(‘fld’,2);
$config['upload_path'] = ‘./uploads/’;
$config['allowed_types'] = ‘gif|jpg|png’;
$this->load->library(‘upload’, $config);if ( ! $this->upload->do_upload($uploadFile))
{
$error = array(‘error’ => $this->upload->display_errors());$this->load->view(‘upload_form’, $error);
}
else
{
$data = array(‘upload_data’ => $this->upload->data());$this->load->view(‘upload_success’);
}}
File: upload_form.php(views).
<script type=”text/javascript” src=”<?=base_url()?>/ajaxfileupload.js”></script>
<input type=”file” name=”uploadfile” id=”uploadfile” />
<intpy type=”button” name=”upload” id=”upload” value=”Upload” /><script>
$(function(){
$(‘#upload ‘).click(function(){$.ajaxFileUpload
(
{url: “ajaxupload/doupload/fld/uploadfile”,
secureuri:false,
fileElementId: ‘uploadfile’,
dataType: ‘json’,
success: function (data, status)
{if(typeof(data.error) != ‘undefined’)
{
if(data.error != ”)
{
alert(data.error);
}else
{
alert(data.msg);
}
}},
error: function (data, status, e)
{
alert(e);}
}
);
});
});</script>
Dowmlad ajaxfileuplaod.js .


Dear Author tandukar.com !
I do not believe.
I want to quote your post in my blog. It can?
And you et an account on Twitter?
Hi Majitonic you can twit me as “tandubhai” in twitter.
Sure , you can quote in your blog.
you must echo json_encode($error) so the view can pick up the result
Dear sir.
I think u know me.Plz write a code in codeignitor to upload multiple file with database insertion and updating part.
Looks great but incomplete
uri_assoc() ???
That’s an undefined function – what is it?
Hi, am trying to implement your code. I get an error:
syntax error: invalid token <
do you have any idea why?