![]() |
upload multiple files to multiple folders - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: upload multiple files to multiple folders (/showthread.php?tid=12555) Pages:
1
2
|
upload multiple files to multiple folders - El Forum - 10-23-2008 [eluser]PHP Programmer[/eluser] i am trying to upload multiple files to multiple folders. For this I am using this code: function do_upload() { $files = array('userfile1'=>array('upload_path'=>'./uploads/file1/','allowed_types'=>'gif|jpg|png','max_size'=>100), 'userfile2'=>array('upload_path'=>'./uploads/file2/','allowed_types'=>'gif|jpg|png','max_size'=>100)); $this->load->library('upload'); //Below Line Added By ANUJ foreach($files as $field=>$settings) { $this->upload->initialize($settings); //Above Line Added By ANUJ if ( ! $this->upload->do_upload($field)) { $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', $data); echo $data['upload_data']['file_name']; } } } // Multi Files function do_upload() { $config['upload_path'] = './uploads/file1/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $this->load->library('upload'); foreach($_FILES as $key => $value) { if( ! empty($key)) { $this->upload->initialize($config); if ( ! $this->upload->do_upload($key)) { print_r($errors[] = $this->upload->display_errors()); } else { //$this->Process_image->process_pic(); } } } } In 1st code, it comes an error "Unable to find a post variable called userfile." How to resolve it? The 2nd code runs fine separately but not when merge with 1st code. Please suggest how to overcome this problem? TIA upload multiple files to multiple folders - El Forum - 10-23-2008 [eluser]PHP Programmer[/eluser] Some changes in previous post: The files are of different types too ie gif|png|jpg and avi|swf|fla and doc|pdf|txt upload multiple files to multiple folders - El Forum - 10-24-2008 [eluser]Mason Kessinger[/eluser] I'm hoping to find out how to do exactly that. So I'm going to post here in the hopes that someone can come along and rain down a little wisdom on the subject. I'm hoping to be able to put something like this into a Library or extend the native Uploader controller and put it on the Wiki for all to benefit from. This seems like such a useful tool, but I am also unable to figure out how to solve this from the many posts on this subject. Good luck! Please let us know if you find a solution! upload multiple files to multiple folders - El Forum - 10-24-2008 [eluser]xwero[/eluser] Multiple file uploads, even with different file types and directories are not that difficult. The magic method in this scenario is initialize. In pseudo code : - load library - initialize - upload first file - initialize - upload second file - repeat until you run out of memory a simple function to process files Code: function multi_upload($configs,$files) upload multiple files to multiple folders - El Forum - 10-27-2008 [eluser]Mason Kessinger[/eluser] This looks really smart. I wonder if you could post some example "in use" code. I just want to be sure that I understand the code entirely. I really feel like this is a huge step closer to helping me understand how this all works. If you could just help one more step I think that would be it. Thanks for your help. upload multiple files to multiple folders - El Forum - 10-27-2008 [eluser]xwero[/eluser] Code: // configs If you add the method to the MY_Upload.php extending class you can remove all the upload-> parts and the loading of the library. upload multiple files to multiple folders - El Forum - 10-27-2008 [eluser]Mason Kessinger[/eluser] Okay, I feel at a loss. I tihnk what you're showing me makes sense but I'm not getting all the right parts speaking to one another. Could you please look at what I'm doing and help explain this? system/application/libraries/multi_upload.php: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); system/application/controllers/cms/portfolio.php : Code: function edit($id = FALSE){ system/application/cms/portfolio/edit.php (after output) : Code: <form action="http://localhost:9070/cms/portfolio/edit" method="post" id="edit_form" name="edit_form" enctype="multipart/form-data"> Results in the following output: A PHP Error was encountered Severity: Warning Message: Missing argument 1 for Multi_upload::multi_upload(), called in /Users/kessinger/Sites/xer001_9070/system/libraries/Loader.php on line 873 and defined Filename: libraries/multi_upload.php Line Number: 5 A PHP Error was encountered Severity: Warning Message: Missing argument 2 for Multi_upload::multi_upload(), called in /Users/kessinger/Sites/xer001_9070/system/libraries/Loader.php on line 873 and defined Filename: libraries/multi_upload.php Line Number: 5 A PHP Error was encountered Severity: Notice Message: Undefined property: Multi_upload::$load Filename: libraries/multi_upload.php Line Number: 6 Fatal error: Call to a member function library() on a non-object in /Users/kessinger/Sites/xer001_9070/system/application/libraries/multi_upload.php on line 6 upload multiple files to multiple folders - El Forum - 10-27-2008 [eluser]xwero[/eluser] If you name the library multi_upload the method should be named differently otherwise php thinks it's the class constructor method. Code: // MY_Upload.php upload multiple files to multiple folders - El Forum - 11-06-2008 [eluser]Ignacio[/eluser] Here is an error, I fix it. Works good. Code: $this->initialize($config[$[$i]); Code: $this->initialize($configs[$i]); -- This is excellent, the problem is, if an error happen, you need to re-upload all the files again, I'm trying to fix this but its really hard. upload multiple files to multiple folders - El Forum - 12-03-2008 [eluser]calingrim[/eluser] I have a problem with this... So i got: Code: <? And my controller: Code: function add_set() { Code: <?=form_open_multipart('admin/admin_albums/add_set')?> The problem is with 3 or more files. If I upload 2 files everything wroks just fine but when i try to upload 3 or more it keeps repeating the first two. Example: file1 = picA.jpg; file2 = picB.jpg; file3 = picC.jpg; The script will upload: picA.jpg, picB.jpg and picA1.jpg. Thanks in advance. |