I’m trying to upload files using an Ajax call; I’ve been searching the webs for the last few days and found some plugins; however, is it possible to use my current function:
it works as a standalone function to be called; but I can’t get it to be called via JS.
Thanks.
function changeBookPicture($table, $bookId)
{
$config['upload_path'] = "Marketplace_Pictures/$table/";
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '1000000';
$config['overwrite'] = true;
$config['file_name'] = $bookId;
$this->load->library('upload', $config);
$this->upload->do_upload();
if ( ! $this->upload->do_upload())
{
//upload fail
$data['error'] = array('error' => $this->upload->display_errors());
}
else
{
//upload succeeds
$data['error'] = array('upload_data' => $this->upload->data());
//get uploaded file information
$img_data = $this->upload->data();
//get File extension
$ext = $img_ext = $img_data['file_ext'];
//add extension to db
$this->marketplace_model->addUserImage($table, $bookId, $ext);
}
}
This is how I want to call the upload function:
$("#upload-button").click(function(e){
e.preventDefault();
//make ajax call
});
