Welcome Guest, Not a member yet? Register   Sign In
File Upload -You did not select a file to upload Error
#1

[eluser]the_unforgiven[/eluser]
Im getting the error:
You did not select a file to upload.

But i did select a file to upload and have everything set up like so:

Controller
Code:
//Uploads
function _do_upload_file()
{
     // Config
  $config['upload_path']   = './assets/uploads/';
     $config['allowed_types'] = 'png|jpg|doc|docx|pdf|rtf|txt';
     $config['max_size'] = '3000';

     $this->load->library('upload', $config);
  $this->upload->initialize($config);
    
     if (!$this->upload->do_upload('userfile'))
     {
         $this->form_validation->set_message('_do_upload_file', $this->upload->display_errors());
         return FALSE;
    
     }
     else
     {
   $filedata = $this->upload->data();
   $this->filename = $filedata['file_name'];
    // print_r($filedata);
         return TRUE;
     }
}
function addnews()
{
  if ($this->session->userdata('username')) {
  $this->form_validation->set_rules('title', 'News Title', 'required');
  $this->form_validation->set_rules('body', 'News Body', 'required');
  $this->form_validation->set_rules('userfile', 'Your File', 'callback__do_upload_file'); //Callback for errors

  if ($this->form_validation->run() == FALSE)
  {
   $data['main_content'] = 'addnews';
   $data['title']= 'Add News Post';
   $this->load->view('template', $data);
  }
  else
  {
   $this->admin_model->insertnews();
   $data['message'] = $this->session->set_flashdata('message','News item successfully stored.');
   redirect('admin/news', $data);
  }
  }
   else {
    echo '[removed]
        alert("Sorry you MUST be logged in to view this page, please login!");
        location = "../";
    [removed]';
   }
  
}

Model
Code:
function insertnews()
{
  $data = array(
   'title' => $this->input->post('title'),
   'body' => $this->input->post('body'),  
  );
  $image_data = $this->upload->data();
  $data['image'] = $image_data['file_name'];
  
  $this->db->insert('news', $data);
}

View
Code:
<h1>Add News Item</h1>
&lt;?php echo validation_errors('<div class="error">', '</div>'); ?&gt;
&lt;?php
$attributes = array('class' => 'email', 'id' => 'loginform');
echo form_open('admin/addnews', $attributes);

$upload = array('name'=>'userfile','id'=>'userfile');
?&gt;

<table>
<tr><td>News Title:</td><td>&lt;?php echo form_input('title'); ?&gt;</td></tr>
  <tr><td>Body:</td><td>&lt;textarea name="body" id="description"&gt;&lt;/textarea>&lt;?php echo display_ckeditor($ckeditor1); ?&gt;</td></tr>
<tr><td>Add File:</td><td>&lt;?php echo form_upload($upload); ?&gt;</td></tr>
</table>

&lt;?php echo form_submit('submit', 'Create News Item'); ?&gt;

&lt;?php echo form_close();?&gt;
#2

[eluser]the_unforgiven[/eluser]
Anyone help on this?
#3

[eluser]Mauricio de Abreu Antunes[/eluser]
Code:
echo form_open('admin/addnews', $attributes);

This is not a multipart form. :-)
#4

[eluser]the_unforgiven[/eluser]
or sH*t yer thanks for pointing that out knew it would be something simlpe
#5

[eluser]Mauricio de Abreu Antunes[/eluser]
ASUGUASHUISAHIOHASUIE! I LOLed here. :X
#6

[eluser]Unknown[/eluser]
I have the same problem, I had to use only HTML, is an error in the helper form
#7

[eluser]Zulkifli Said[/eluser]
try to use form_open_multipart

Code:
&lt;?php echo form_open_multipart('c_mading/do_upload'); ?&gt;
#8

[eluser]InsiteFX[/eluser]
Try to use code tags when posting code!




Theme © iAndrew 2016 - Forum software by © MyBB