Form Generation Library |
[eluser]happydude[/eluser]
@hugle Normally, we set the default upload path for the Form Generator Library in the form.php config folder. In my controller, I want some methodss to upload images to different folder depending on the method. I want admin/products to upload images to assets/products I want admin/categories to upload images to assets/categories I want admin/brands to upload images to assets/brands What I am looking for is a way to change the file upload path as the case may be in the method. I don't think FGL allows one to set config on the fly. I then decided to try changing the way the config array is defined, it still didn't work. Any help will be appreciated. Thanks in advance. @Mat-Moo Since are using form generator library to upload, I don't think one has access to file uploading library and cannot really use or chain ->upload(var, label, config)
[eluser]dinhtrung[/eluser]
@happydude: Just upload the file into your /tmp/ folder. Then in the model, you move the file the way you want it. For example: Code: /* Controller */ Code: /* Controller */
[eluser]Mat-Moo[/eluser]
Why not just set a temp location, and once uploaded move it to the correct location then?
[eluser]macigniter[/eluser]
[quote author="happydude" date="1261042603"]@hugle Normally, we set the default upload path for the Form Generator Library in the form.php config folder. In my controller, I want some methodss to upload images to different folder depending on the method. I want admin/products to upload images to assets/products I want admin/categories to upload images to assets/categories I want admin/brands to upload images to assets/brands What I am looking for is a way to change the file upload path as the case may be in the method.[/quote] This really isn't rocket science ;-) and by the way is clearly documented in the user guide. I just ran a quick test with the latest pre-release version of the library and have successfully managed to upload two files from two different upload elements within the same form (!) into different folders. All I did was: Code: ...
[eluser]happydude[/eluser]
Funny, I never noticed this previously in the userguide. Actually, after going through the userguide and mapping stuff into my head, I now rely more on the reference guide which doesn't have config in its syntax. Thanks for the heads up though. I've got another problem though. Is there any other way I can access the parameters from the image uploaded asides using the $_FILES array? This is because spaces are automatically removed from the file uploaded $_FILES['userfile']['name'] still leaves spaces in the name which I'll store in the db and will need to call the stored image later.
[eluser]macigniter[/eluser]
[quote author="happydude" date="1261105568"] I've got another problem though. Is there any other way I can access the parameters from the image uploaded asides using the $_FILES array?[/quote] Code: $this->form->upload('file_upload', 'Upload File'); You can access the data either in the model: Code: function do_db_stuff(&$form, $data) or after $this->form->validate() Code: if ($this->form->valid)
[eluser]piyush138[/eluser]
go through this link http://ellislab.com/codeigniter/user-gui...ading.html
[eluser]happydude[/eluser]
[quote author="macigniter" date="1261106016"][quote author="happydude" date="1261105568"] I've got another problem though. Is there any other way I can access the parameters from the image uploaded asides using the $_FILES array?[/quote] Code: $this->form->upload('file_upload', 'Upload File'); You can access the data either in the model: Code: function do_db_stuff(&$form, $data) or after $this->form->validate() Code: if ($this->form->valid) print_r($post_data['file_upload']) is displaying blank.... Nothing whatsoever on my side. When I did this in my model, function do_db_stuff(&$form, $data) { print_r($data['file_upload']); } I got this: A PHP Error was encountered Severity: Notice Message: Undefined index: userfile Filename: models/product_model.php Line Number: 12 I'm pretty confused now. All the while, the images get uploaded, its the parameters that are not returned and I need to store them in the database (They only show up when I use $_FILES but the name is different from that of the file uploaded).
[eluser]macigniter[/eluser]
[quote author="happydude" date="1261168946"] I'm pretty confused now. All the while, the images get uploaded, its the parameters that are not returned and I need to store them in the database (They only show up when I use $_FILES but the name is different from that of the file uploaded).[/quote] Which version of the library are you using? Please post your controller and model...
[eluser]happydude[/eluser]
I'm using the latest version you provided. 0.2.2 Pre-release Part of the controller that handles the form and image upload is posted below. Please note that I loaded my model in the constructor like this - $this->load->model('product_model', 'product'); Code: function add() The model is really not necessary as I use if($this->form->valid) and I do some processing on the data before saving it in the database as you can see in the controller below. But in order to test the code you provided previously, I commented out the if($this->form->valid) block, changed ->validate(); to model('product_model', 'add') and quickly created the model below. Of course, it gave me the error I posted earlier. Code: function add(&$form, $data) |
Welcome Guest, Not a member yet? Register Sign In |