CodeIgniter Forums

Full Version: issue with uploader
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am trying to understand the uploader.  I have a uploader.php with the config in and it does work if I break the code inside it, so I know its being loaded.

I have this process at the moment and it works and adds the bit to the database but its not uploading the image.

PHP Code:
public function upload_image_process(){
 
           
            $upload_image 
$this->input->post('upload_image');
 
           
            $data 
= array(
 
           
                
            
            
'name' => $this->input->post('image_name')
 
           );
 
          
            if 
(is_array($data) && count($data)>0){
 
             
              $this
->upload->do_upload($upload_image);
 
             $this->Admin_model->add_content($data'image_uploads'); 
 
             $this->session->set_flashdata('message''Image uploaded.');
 
             redirect('admin/dashboard');  
            
            
} else {
 
           
            redirect
('admin/dashboard');
 
           }
 
       


I feel i am not using it right but I have looked at the docs and I cannot see any issue.

Thanks,

Doomie
you are not showing your code - you have to create the configs and load the upload library with the configs.

the most common issue is that you have not changed the permissions on the folder you are trying to upload to.
otherwise i would google for a tutorial that will take you step by step.
The config is being auto loaded in uploader.php as stated above which is in the tutorial in the docs, the folder is also set to 777 as in the docs.
You are redirecting to the admin/dashboard in all circumstances, but you could be missing an error message.

Try doing something like:
PHP Code:
if ( ! $this->upload->do_upload($upload_image))

 
  $error $this->upload->display_errors('''');
 
  show_error('Upload Errors: '.$error401'Upload Error');
 
  exit;


Perhaps your path/to/directory is not set correctly, or it is the image type, or the size etc etc. You should always be checking and reporting back to the user when an error occurs. Otherwise, how do you or the user know what is going on?

Hope that helps,

Paul

PS Am just using the 'show_error' for simplicity here, it is a quick solution while testing or developing. Of course normally you would have a user error view and/or error logging in place of some description.
I am getting the following error.

Upload Errors: You did not select a file to upload.

This is the form section of it.

PHP Code:
<?php echo form_upload(array('id' => '1''name' => 'upload_image''class' => 'form-control')); ?>


I really have no idea why it is saying that as I have unless it's not pulling it to the process.
Hi,

OK, at least you have an idea now of why your file is not uploading. It is probably a field name error. I see in your controller you are referring to

PHP Code:
$this->input->post('image_name'

and

PHP Code:
$this->input->post('upload_image'

Check what the name of your file input field actually is.

Hope that helps,

Paul.

PS Just noticed you quoted your form section above. Can you paste the HTML of the form that is being generated?

Try this: Change
PHP Code:
$this->upload->do_upload($upload_image); 

to
PHP Code:
$this->upload->do_upload('upload_image'); 
again its easier to help you if you show all your code. the form open needs to be multipart
form_open_multipart('uploadphoto');

the form field needs to be type=file
<input type="file" name="filename" size="20" />