Uploading Multiple Files As Email Attachment - 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: Uploading Multiple Files As Email Attachment (/showthread.php?tid=57626) |
Uploading Multiple Files As Email Attachment - El Forum - 03-28-2013 [eluser]RaGe10940[/eluser] Hello CI Community, I have a email system that I need multiple file attachments to be sent in from one upload input. The system does : 1) Use student ID, First and last name, 2) pulls the email from the DB with the 3 fields the staff member typed 3) an email will be sent to a student with the attachments I have it working (sorta)... however for only one document though... What I have done : 1) The emailing works perfectly. 2) The problem arises when I go do the uploading 3) I have taken a look at my upload directory, however... ONLY ONE form is uploaded not both. This is my view : Code: <div id="attachment"> This is just the uploading part the rest of the view is not needed for this question : my upload part of my controller : Code: $config['upload_path'] = '/usr/local/var/www/Test/ci/uploads/'; After the else part of my controller (the email stuff) : Code: $return = $this->upload->data(); Again to reidirate my email function IS WORKING The problem occurs when I try to upload. Only one file is uploaded not the other (i am testing with .txt files, and I am getting no errors) Any help would be awesome. Regards, Uploading Multiple Files As Email Attachment - El Forum - 03-28-2013 [eluser]TheFuzzy0ne[/eluser] Have you tried outputting the $_FILES array to make sure it's in the format you expect it to be in? Your code sends two emails (one for each file), but after the first one is sent successfully you're redirecting - D'OH! Uploading Multiple Files As Email Attachment - El Forum - 03-28-2013 [eluser]RaGe10940[/eluser] [quote author="TheFuzzy0ne" date="1364483332"]Have you tried outputting the $_FILES array to make sure it's in the format you expect it to be in? Your code sends two emails (one for each file), but after the first one is sent successfully you're redirecting - D'OH![/quote] I'm sorry I don't understand? My code sends to two emails? It shouldn't... only one email can be queried due to how I have my WHERE clause set up. Can you elaborate? Uploading Multiple Files As Email Attachment - El Forum - 03-28-2013 [eluser]RaGe10940[/eluser] Code: array(1) { ["userfile"]=> array(5) { ["name"]=> string(9) "test2.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpuuimFq" ["error"]=> int(0) ["size"]=> int(13) } } Is what the vardump of the $_FILES is outputting Uploading Multiple Files As Email Attachment - El Forum - 03-28-2013 [eluser]TheFuzzy0ne[/eluser] Indeed, I can. Code: $config['upload_path'] = '/usr/local/var/www/Test/ci/uploads/'; Uploading Multiple Files As Email Attachment - El Forum - 03-28-2013 [eluser]TheFuzzy0ne[/eluser] [quote author="RaGe10940" date="1364484794"] Code: array(1) { ["userfile"]=> array(5) { ["name"]=> string(9) "test2.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpuuimFq" ["error"]=> int(0) ["size"]=> int(13) } } Is what the vardump of the $_FILES is outputting[/quote] Now that's odd, don't ya think? There's only one file there. Maybe you need to upload an array? Code: <div id="attachment"> Ta-da! Now you just need to modify your code to process the $_FILES array properly. Uploading Multiple Files As Email Attachment - El Forum - 03-28-2013 [eluser]RaGe10940[/eluser] Code: function sendemail() { with the current controller, and this view : <div id="attachment"> <input type="file" name="userfile[]" multiple="" /> </div> I keep getting this error : You did not select a file to upload. I do though however get this when I dump $value : Code: rray(5) { ["name"]=> array(2) { [0]=> string(8) "test.txt" [1]=> string(9) "test2.txt" } ["type"]=> array(2) { [0]=> string(10) "text/plain" [1]=> string(10) "text/plain" } ["tmp_name"]=> array(2) { [0]=> string(14) "/tmp/phpG4y0OF" [1]=> string(14) "/tmp/phpoG9lSJ" } ["error"]=> array(2) { [0]=> int(0) [1]=> int(0) } ["size"]=> array(2) { [0]=> int(11) [1]=> int(13) } } both files are now in the array Uploading Multiple Files As Email Attachment - El Forum - 03-28-2013 [eluser]TheFuzzy0ne[/eluser] Oh yes, I forgot. Sorry! The uploads library doesn't support multiple uploads. You'll need to extend it to add that functionality. It shouldn't be too difficult to get working. I'm going to try and find the time to submit that as a feature to CodeIgniter 3. Until now, I've wanted to contribute, but I've been at a loss as to what to contribute. Now I have a decent contribution to make, thanks to you! Thanks! Uploading Multiple Files As Email Attachment - El Forum - 03-28-2013 [eluser]RaGe10940[/eluser] There actually is extension to the library on GitHub https://github.com/nicdev/CodeIgniter-Multiple-File-Upload I'ma come back with my results. Thanks for letting me know and yes that is a very big constraint of CodeIgniter. It forces one to do a upload with the input (x amount of times rather then just holding ctrl + mouse click)... fail on CI's part. Thanks for the help though. And if PHP the right way is your website then I love you <3 Uploading Multiple Files As Email Attachment - El Forum - 03-28-2013 [eluser]RaGe10940[/eluser] Using this library : https://github.com/nicdev/CodeIgniter-Multiple-File-Upload I am able to upload multiple files to my directory that works fine and dandy and even the email works However now only one email is sending an attachment (again) however I noticed a problem when trying to send and array... I am getting this : Code: array(14) { ["file_name"]=> string(9) "test2.txt" ["file_type"]=> string(10) "text/plain" ["file_path"]=> string(35) "/usr/local/var/www/Test/ci/uploads/" ["full_path"]=> string(44) "/usr/local/var/www/Test/ci/uploads/test2.txt" ["raw_name"]=> string(5) "test2" ["orig_name"]=> string(9) "test2.txt" ["client_name"]=> string(9) "test2.txt" ["file_ext"]=> string(4) ".txt" ["file_size"]=> float(0.01) ["is_image"]=> bool(false) ["image_width"]=> string(0) "" ["image_height"]=> string(0) "" ["image_type"]=> string(0) "" ["image_size_str"]=> string(0) "" } which is the $this->upload->data() now I run this through : Code: foreach ($this->upload->data() as $fileData) { However the problem is now that the array is not adding the second, third, fourth, fifth file... it only adds one file. in my view : div id="attachment"> <input type="file" name="userfile[]" multiple /> </div> and still nothing.. I tried using this library as well : https://github.com/stvnthomas/CodeIgniter-Multi-Upload and still the same problem. Any tips? |