i’m trying to create form which with which i can upload text and image both. But when i enter the information the texts only get saved but the image doesn’t seem to appear the folder.
Part of my controller file
$form_data = array(
'address' => set_value('address'),
'area' => set_value('area'),
'lat' => set_value('lat'),
'lng' => set_value('lng'),
'subject' => set_value('subject'),
'problem' => set_value('problem'),
'image' => '',//what to put here???
'time' => $now,
'register_id' =>set_value ('register_id'),
'category_id' => set_value('category_id'),
'city_city_id' => set_value('city_city_id'),
'status_status_id' => set_value('status_status_id')
);
if ($this->report_model->SaveForm($form_data) == TRUE)
{
redirect('report/success');
}
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->upload->initialize($config);
$this->load->library('upload', $config);
}
View file
$attributes = array('class' => '', 'id' => '');
echo form_open('report', $attributes); ?>
<p>
<label for="problem">problem detail:</label>
<?php echo form_error('problem'); ?>
<br /><input id="problem" type="text" name="problem" value="<?php echo
set_value('problem'); ?>" />
</p>
<p>Upload a image:
<?php echo form_open_multipart('report/do_upload');?>
<input type="file" name="image" size="20" />
please help
By default the file uploaded is called
userfileChange that
imagetouserfilefor your upload input element.Otherwise define
imageas the name/id to use by the upload class.Ref: http://codeigniter.com/user_guide/libraries/file_uploading.html
ACTUALLY… seems you are all over the place (multiple forms?)
Just go to the reference link I provided, and start a single form, follow the user guide for best details, I think you are just confusing how to create a form under CI.