I'm currently developping some forms for my school project with CodeIgniter.
The idea is that I have a form with image upload. I'm trying to do it dynamically with Ajax but it seems not working at all. I tried the non-dynamic version with php and It works perfectly, my images are in my folder and I have no problem with it.
I tried like 5 or 6 plug-ins with no results, it is certainly my fault but I don't know where I did a mistakes.
<---Controller--->
if($result = $this->images_model->add_bdd())
{
$data['uploaded'] = $result;
$data['message_upload'] = 'Image uploader avec succès.';
$this->template->set_title('Upload successful');
$this->template->view('add_places',$data);
}
else
{
$this->template->set_title('Upload failed');
$this->template->view('add_places');
}
<--Model-->
function add_bdd()
{
$config = array(
'allowed_types' => 'jpg|jpeg|tiff',
'upload_path' => $this->gallery_path,
'max_size' => 2000,
'remove_spaces' => TRUE,
'overwrite' => FALSE
);
$this->load->library('upload',$config);
if ($this->upload->do_upload())
{
$data_img = $this->upload->data();
$exif = $this->exif_extractor->coords($data_img['full_path']);
$data = array(
'titre' => 'titlecontent',
'url' => base_url('images/'.$data_img['file_name']),
'url_min' => base_url('images/'.$data_img['raw_name'].'_min'.$data_img['file_ext']),
'alt' => 'cover_contentName',
'id_users' => $this->session->userdata('id'),
'date_upload' => date('Y-m-d H:m'),
'date_modified' => date('Y-m-d H:m'),
'lat' => $exif[0],
'long' => $exif[1],
);
$this->db->insert('pictures',$data);
return $exif;
}
else
{
return false;
}
}
<--View-->
<form action="http://localhost:8888/project/images/add" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="userfile" value="Image de couverture" />
<button name="upload" type="button" id="upload">Upload</button>
<input type="submit" name="submit" value="Publish Place" />
</form>
Can anyone give me a jQuery plugin to upload images dynamically and send back to the script my images with the path and others data that I want to return ?
I can't paste like all the code I made for jQuery, but I really need help about it. It's been 2 days that I'm on it!
Thanks for your help.
Thanks for you help, I change my dynamic about the script so now, it works perfectly with what I have to do.
There is the script for my upload system :
<-- VIEW (upload_img)-->
<-- CONTROLLER -->
<-- MODEL -->
<-- JS-SCRIPTS -->
First of all include :
-jQuery
-browserPlus
-Plupload
(Plupload Script)
Now add this script in an empty file:
Do your own customization and that's it, no need extra script like you can see on website like copy/paste all script from a php file to a controller, just add 'file' inside do_upload and everything's gonna work fine !
Have a nice day guys, hope it's help.
Simon
Without the Javascript code there's little anyone can do for you.
Check out this tutorial on Nettuts+ which goes into depth of the basic idea that you're after so that you better understand, debug and adjust your code.
Also, I barely use jQuery plugins as I find it easier to code one that better suits the needs of my current project so I can't recommend any.
Does the add_bdd() function return false?
I have used CodeIgnitor to do this very thing and I have found that the filters you specify are usually why you do not get the file uploaded. You should add more code to the section where
if ($this->upload->do_upload())
is false and print out the debug code using the following:See here for more info: http://codeigniter.com/user_guide/libraries/file_uploading.html
Keep in mind that if you are calling this via AJAX, you will need a means to see the debug result such as printing the echo'ed debug result to an HTML element on your calling page. You could also print the iformation using a tool like Firebug.