| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Registered User
Join Date: Feb 2008
Posts: 1
|
need help for codeignitor upload image
in controller <?php class Form extends Controller { function index() { parent::Controller(); # loaders $this->load->library('validation'); $this->load->library('email'); $this->load->helper(array('form', 'url', 'array')); $this->load->library('upload'); $this->upload->do_upload(); $rules['YourName'] = "required"; $rules['email'] = "required|valid_email"; //$rules['image'] = "required"; $this->validation->set_rules($rules); #Input and textarea field attributes $data['YourName'] = array('name' => 'YourName', 'id' => 'YourName'); $data['email'] = array('name' => 'email', 'id' => 'email'); $data['comments'] = array('name' => 'comments', 'id' => 'comments', 'rows' => 3, 'cols' => 48); // $data['userfile'] = array('name' => 'userfile', 'id' => 'image'); $data['userfile'] = array('userfile' => $this->upload->data(),'name' => 'userfile', 'id' => 'image'); echo "image file".$data['userfile'] ; // $image = array('upload_data' => $this->upload->data()); //resize the image // $this->resize_image('GD2', $image['upload_data']['full_path'], 100, 100); //$image_data['image_name'] = $image['upload_data']['file_name']; //$data = array('upload_data' => $this->upload->data()); if ($this->validation->run() == FALSE) { $this->load->view('form_view', $data); } else { $YourName = $this->input->post('YourName'); $email = $this->input->post('email'); $comments = $this->input->post('comments'); $userfile = $this->input->post('userfile'); $this->load->view('formsuccess'); $this->load->model('Form_model','', TRUE); $this->Form_model->add_participant(); } } function results() { $this->load->helper(array('form', 'url', 'array')); $this->load->model('Form_model', '', TRUE); $data['query'] = $this->Form_model->list_participants(); $this->load->view('results', $data); } } ?> ---------------------------------------------- View ----------------------------------------------- <? <div class="formArea"> <div class="errors"><?php echo $this->validation->error_string; ?></div> <?php echo form_open_multipart('Form/index'); ?> <p class="formBold"><label for="YourName">YOUR NAME</label></span><br> <?php echo form_input($YourName); ?> <p class="formBold"><label for="email">YOUR EMAIL ADDRESS</label></span><br> <?php echo form_input($email); ?> <p class="formBold"><label for="comments">COMMENTS</label></span><br> <?php echo form_textarea($comments); ?> <p class="formBold"><label for="userfile">UPLOAD YOUR PHOTO</label></span><br> <?= form_upload($userfile); ?> <?php echo form_submit('submit', 'Submit'); ?> <?php echo form_close(); ?> ----------------------------------------------- model --------------------------------------------- <?php class Form_model extends Model { function Form_model() { parent::Model(); } function add_participant() { $YourName = $this->input->post('YourName'); $email = $this->input->post('email'); $comments = $this->input->post('comments'); echo $YourName; $userfile = $this->input->post('userfile'); echo "test".$userfile."<br>" ; $querytest =$this->db->query("INSERT INTO participants (id, YourName, email, comments, userfile) VALUES(NULL, '$YourName', '$email', '$comments', '$userfile')"); echo "query".$querytest; } function list_participants() { $query = $this->db->query("SELECT * FROM participants"); return $query; } } ?> --------------------------------------------------------------------------- but userfile not upload ..tell what is the peoblem in this code pz |
|
|
|
|
|
#2 (permalink) |
|
vague™
Join Date: Mar 2004
Location: Glasgow
Posts: 5,337
|
A better place to ask; Powered By ExpressionEngine | CodeIgniter Forums |
|
![]() |