CodeIgniter Forums

Full Version: error : You did not select a file to upload
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]senz[/eluser]
I want to try uploading the image files but that appears is the following message :
"You did not select a file to upload". Though I have followed the instructions to upload the files in CodeIgniter. What is means of this error message?

El Forum

[eluser]Ivar89[/eluser]
That you did not select a file to upload..(A)

El Forum

[eluser]pickupman[/eluser]
[quote author="Ivar89" date="1274199136"]That you did not select a file to upload..(A)[/quote]
Either that or you did not name your fields matching your upload configuration. The input field should be named "userfile", unless you have set differently in your config array.

El Forum

[eluser]senz[/eluser]
I have included a file to be uploaded but still have the message. So what does that mean "userfile" and what should I configure? I have input files in the view and I gave the name "thumbnail", then I use the command $ this-> upload-> do_upload ('thumbnail') inside the controller. But still the error message appears. Is there another solution?

El Forum

[eluser]pickupman[/eluser]
With what you have explained seems to make sense, however without seeing any code it's hard to say for sure. A neat little thing about CI is
Code:
$this->output->enable_profiler(TRUE); //Put in your constructor of your controller or at the beginning of a method

It will output a lot of info about POST, queries, execution times. Might be helpful why this may be happening. You also haven't mentioned about your server environment Windows/Linux?. Maybe it's a folder permissions issue.

El Forum

[eluser]senz[/eluser]
[quote author="pickupman" date="1274255597"]With what you have explained seems to make sense, however without seeing any code it's hard to say for sure. A neat little thing about CI is
Code:
$this->output->enable_profiler(TRUE); //Put in your constructor of your controller or at the beginning of a method

It will output a lot of info about POST, queries, execution times. Might be helpful why this may be happening. You also haven't mentioned about your server environment Windows/Linux?. Maybe it's a folder permissions issue.[/quote]

The upload_view code like this :
Code:
<?
        echo $error;
        foreach($asset as $row)
        {
            $id = $row->id;
            $name = $row->name;
            $image = $row->image;
        echo form_open_multipart('upload/update_upload');
    ?>
        <input type="hidden" name="id" value="<?=$id;?>"/>
        <input type="text" name="name" size="20" value="<?=$name;?>"/><br/>
        <img src="&lt;?=base_url();?&gt;public/images/&lt;?=$image;?&gt;"/><br/>
        &lt;input type="file" name="image"/&gt;&lt;br/>
        &lt;input type="submit" value="Update" name="submit"&gt;    
    &lt;?
        }
        echo form_close();
    ?&gt;

And the upload controller like this :
Code:
function update_upload()
    {
        $this->load->library('upload');
        
        $config['upload_path'] = './public/images/promo';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '500';
        $config['max_width'] = '1024';
        $config['max_height'] = '768';
        
        $this->upload->initialize($config);
        
        $field_name = "image";
        $img = $this->input->post('image');
        if (!$this->upload->do_upload($field_name))
        {
            $error=array('error'=>$this->upload->display_errors());
            $this->load->view('upload_view',$error);
        }
        else
        {
            $data= $this->upload->data();
            foreach($data as $value)
            {
                $name_file = "promo/".$value;
                break;
            }
            $this->upload_model->update($name_file);
            redirect('upload/view_upload', 'refresh');
        }
    }

And i use windows for web server.

El Forum

[eluser]pickupman[/eluser]
Even though you are on windows, you still to check file permissions. This may not be the issue yet, but for 2000,Server 2k3/8, XP Pro, Vista, & 7 you have to give Full Access on your temporary upload folder. You can usually find this with phpinfo(); which will probably be something like c:\windows\tmp, c:\windows\temp, or c:\wamp\tmp(Wamp Server).

I did notice a few errors in the code. Your foreach loop is before the open form tag, but the form_close tag is after the foreach. In a sense you are opening the form multiple times but only closing it once.

Here is a working example of your code with a few changes (form validation).
Code:
//Controller
function index(){
        
        //Set test data
        $data['asset'] = (object)array('id'=>'10' , 'name' =>'John Doe', 'image' => 'home-banner.jpg');
        
        $this->load->view('upload_view',$data);
    }
    
    function update_upload()
    {
        $this->load->library(array('upload','form_validation'));
        
        $this->form_validation->set_rules('id', 'id', 'required|trim');
        $this->form_validation->set_rules('name','name', 'required|trim');
        
        $config['upload_path'] = './uploads/images';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '500';
        $config['max_width'] = '1024';
        $config['max_height'] = '768';
            
        $this->upload->initialize($config);
        
        //Make sure form fields are completed
        if($this->form_validation->run() == TRUE){
            
            $img = $this->input->post('image');
            
            //Check if file was uploaded
            if (!$this->upload->do_upload('image'))
            {
                //Test data
                $data['asset'] = (object)array('id'=>'10' , 'name' =>'John Doe', 'image' => 'home-banner.jpg');
                
                $data['error'] = $this->upload->display_errors();
                $this->load->view('upload_view',$data);
            }
            else
            {
                //Uploaded Completed
                $data = $this->upload->data();
                
                $name_file = "promo/".$data['file_name'];
                
                $this->upload_model->update($name_file);
                redirect('upload/view_upload', 'refresh');
            }
        }else{
            
            //Test data
            $data['asset'] = (object)array('id'=>'10' , 'name' =>'John Doe', 'image' => 'home-banner.jpg');
            
            $this->load->view('upload_view', $data);
            
        }
    }

//View
&lt;?
        if(isset($error))
          echo $error;
          
        echo validation_errors();
        
        $id = $asset->id;
        $name = $asset->name;
        $image = $asset->image;
        
        echo form_open_multipart('upload/update_upload');
    ?&gt;
        &lt;input type="hidden" name="id" value="&lt;?=$id;?&gt;"/&gt;
        &lt;input type="text" name="name" size="20" value="&lt;?=set_value('name',$name);?&gt;"/&gt;&lt;br/>
        <img src="&lt;?=base_url();?&gt;uploads/&lt;?=$image;?&gt;"/><br/>
        &lt;input type="file" name="image"/&gt;&lt;br/>
        &lt;input type="submit" value="Update" name="submit"&gt;    
    &lt;?
      
        echo form_close();
      
    ?&gt;

I'm not sure if your foreach loop is supposed to be creating a upload form for each asset. If so, it would seem that the way you are redirecting you would only have one image update when someone submits the form.

El Forum

[eluser]senz[/eluser]
Thank you pickupman...
Finally, i can solve my problem after i read your code.
Thanks ;-)