EllisLab text mark
Advanced Search
     
error : You did not select a file to upload
Posted: 18 May 2010 07:07 AM
Avatar
Joined: 2010-04-23
20 posts

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?

 Signature 
 
Posted: 18 May 2010 08:12 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2010-03-22
144 posts

That you did not select a file to upload..(A)

 Signature 

- Cotton eye Joe -

 
Posted: 18 May 2010 09:54 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2009-03-30
1317 posts
Ivar89 - 18 May 2010 12:12 PM

That you did not select a file to upload..(A)

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.

 
Posted: 18 May 2010 11:42 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2010-04-23
20 posts

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?

 Signature 
 
Posted: 18 May 2010 11:53 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2009-03-30
1317 posts

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

$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.

 
Posted: 19 May 2010 04:08 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2010-04-23
20 posts
pickupman - 19 May 2010 03:53 AM

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

$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.

The upload_view code like this :

<?
        
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="<?=base_url();?>public/images/<?=$image;?>"/><br/>
        <
input type="file" name="image"/><br/>
        <
input type="submit" value="Update" name="submit">    
    
<?
        }
        
echo form_close();
    
?> 

And the upload controller like this :

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.

 Signature 
 
Posted: 19 May 2010 10:53 AM   [ # 6 ]   [ Rating: 0 ]
Joined: 2009-03-30
1317 posts

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).

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

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.

 
Posted: 20 May 2010 04:00 AM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2010-04-23
20 posts

Thank you pickupman…
Finally, i can solve my problem after i read your code.
Thanks wink

 Signature