CodeIgniter Forums
How to integrate upload file with my form - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to integrate upload file with my form (/showthread.php?tid=59375)



How to integrate upload file with my form - El Forum - 09-27-2013

[eluser]cybersven[/eluser]
Hi,

I'm new to CI and I would like to integrate in an existing form, the upload file.
Before that I've tested the upload from the documentation and it works,
now I've downloaded a complete example form and it works well, so I'm trying to integrate the upload without success, could you help me ?

Here is the controller : https://docs.google.com/document/d/1JtQuUUpBBg6Jvq230sZcNxL_4SyEBPQeYxsk_4Hr5XI/edit?usp=sharing


How to integrate upload file with my form - El Forum - 09-27-2013

[eluser]noideawhattotypehere[/eluser]
Have a form_open_multipart() instead of form_open() in your view, then
Code:
<input type="file" name="userfile" size="20"/>

will be your input file field, place anywhere you want in your view, then after initialization of your upload library call
Code:
$this->upload->do_upload()
If it fails it returns false so you can do some error logging etc. Simple as that, i wont write everything for you as your document is so terrible to work with. (especially that 2342342343 line function)


How to integrate upload file with my form - El Forum - 09-27-2013

[eluser]cybersven[/eluser]
So if I understand do_upload() is a specific function from CI.
Here is the file
https://docs.google.com/file/d/0B4WpmjlDeXeDOEtLTjBZOGVyUHc/edit?usp=sharing
the googledoc has broken the code :/

I've added
Code:
'image_path' => $this->upload->do_upload(),
but I don't see how can I check the function with '$this->form_validation->set_rules' , actually the form is OK and in the database I got a 0 in the image_path...


How to integrate upload file with my form - El Forum - 09-27-2013

[eluser]CroNiX[/eluser]
This should help: http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

$this->upload->do_upload() returns TRUE/FALSE, so that's why you're getting that for the filename.