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

[eluser]mabright[/eluser]
I am using the code from the CI upload class tutorial. The only thing I changed is the upload path, max size and removed max with and height and I keep receiving error "You did not select a file to upload.".

Form
Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>

<?php echo $error;?>

<?php echo form_open_multipart('upload/do_upload');?>

<input type="file" name="userfile" size="20" />

<br /><br />

&lt;input type="submit" value="upload" /&gt;

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

Controller
Code:
&lt;?php

class Upload extends Controller {
    
    function Upload()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url'));
    }
    
    function index()
    {    
        $this->load->view('upload_form', array('error' => ' ' ));
    }

    function do_upload()
    {
        $config['upload_path'] = './user_uploads/msg_attachments/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '2048';
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            
            $this->load->view('upload_form', $error);
        }    
        else
        {
            $data = array('upload_data' => $this->upload->data());
            
            $this->load->view('upload_success', $data);
        }
    }    
}
?&gt;
#2

[eluser]Michael Wales[/eluser]
Make sure file_uploads is turned on in php.ini and that upload_max_filesize and upload_tmp_dir are set correctly.

The only time CodeIgniter produces this particular error is if there is no $_FILES[] array when do_upload() is called.
#3

[eluser]mabright[/eluser]
Always something simple. That did the trick. Thanks.
#4

[eluser]webnology[/eluser]
But what if I don't need to upload a file in my form. I have now an edit form of an article, but the users will not always uplaod an image.

Can I somehow disable the error check?
#5

[eluser]danmontgomery[/eluser]
Code:
if(is_array($_FILES) && !empty($_FILES))
{
    if ( ! $this->upload->do_upload())
        {
           ...
#6

[eluser]webnology[/eluser]
Thx for helping out, but it stays the same. Same error. This is my code:

Code:
if(is_array($_FILES) && !empty($_FILES)) {
  if ( ! $this->upload->do_upload()) {
   $data['error_message'] = array('error' => $this->upload->display_errors());
   $this->load->view('v_edittreatment', $data);
  }    
  else {
   $data = array('upload_data' => $this->upload->data());
   $image_data = $this->upload->data();
  }
}
#7

[eluser]Fatih[/eluser]
Webnology,

Did you find any solution for this issue? I have got same error message. And my php.ini file is adjusted as properly: file_upload (on), upload_max_filesize (200M) and post_max_size (200M). But I couldn't upload a file which size is more than 10 M.




Theme © iAndrew 2016 - Forum software by © MyBB