Reputation: 666
I've been working on a web app using the CodeIgniter framework and I am having trouble with uploading the image.
All the examples I've found online usually only show forms that have one file input
(for example, http://codeigniter.com/user_guide/libraries/file_uploading.html).
The examples often look like this:
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20">
<input type="submit" value="upload">
</form>
But I'm trying to do something more like this:
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20">
<input type="text" name="file_title">
<input type="submit" value="upload">
</form>
Do I need to create two separate forms to accomplish this (one for the image upload and one for the text input)?
Or is it possible to write a function in the controller that can validate and process both the upload and text input simultaneously?
Any resources you could point me to? Thanks a ton!
Upvotes: 3
Views: 3724
Reputation: 16373
You're getting the inputs from the $_POST array and the file from the $_FILES array. There's nothing that should keep you from doing both on the same form.
That being said, you will have to handle errors differently, as upload errors won't show up with the validation errors. What I've done in the past is combined upload errors, validation errors, and my own application errors (ie unauthorized) to use the same view so they all show up in the same place, even if they are being generated by different classes.
Upvotes: 2