1

i have a problem. I'm using CodeIgniter on Xampp Lite and the upload form doesn't work, it returns

You did not select a file to upload.

I declared the form multipart, the input's name is userfile, i set all upload-related vars on, but it doesn't works.

Here's the part of source code:

Controller

 public function send($id,$doupload=false)  {
        $this->load->helper(array('form','url', 'html'));
        $config = 
 array(

                'upload_path'     => dirname($_SERVER["SCRIPT_FILENAME"])."/files/",
                   'upload_url'      => base_url()."files/",
                   'allowed_types'   => "cpp",
                   'overwrite'       => TRUE,
                   'max_size'        => "1000KB", 
                 );         
$this->load->library('upload',$config);         $data=array(            'page_title'=>lang('send_source'),
            'form_sursa'=>array(
                 'name' => 'userfile',
                'id'    => 'sursa',
                 'size' => 20,          ), 
            'id'    => $id      );      
if ($doupload===false)      {
            $this->template->build('problems/send',$data);      }       else        {           if
 ( ! $this->upload->do_upload())            {
                echo ($data['upload_error'] = $this->upload->display_errors());
                $this->template->build('problems/send',$data);          }           else            {
                $data['upload_data'] = $this->upload->data();
                $this->template->build('problems/send',$data);          }       }   }

The form part of template:

 <?php echo form_open_multipart(site_url('probleme/trimite').$id./trimite',array('class'=>'form-horizontal'));

 ?>     
<fieldset>      
<div class="control-group">
 <?php echo form_label(lang('sursa'), 'sursa', array('class' => 'control-label')); ?>
    <input type="hidden" name="MAX_FILE_SIZE" value="99999999" />
    <div class="controls"><?php echo form_upload($form_sursa); ?
><br
 />*<i><?php echo lang('sursa_upload_tip1'); ?></i></div>

                    </div> 
<div class="span7 offset2">
                     <div class="span2" style="text-align: center;">
                         <?php echo form_submit(array('name'  => 'submit', 'value' => 
lang('upload_source'), 'class' => 'btn')); ?>
                     </div>


 <div class="clearfix hspace"></div>
         </div>     
</fieldset>     

.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /
    # rewrite `pub/` requests
    #   IE: [app_path]/themes/default/css/ maps to [app_path]/pub/themes/default/css/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(?:themes|upload)\b.* pub/$0 [L]

    # this adds trailing slash
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ $1/ [R=301,L]

    # Secure directories
    RewriteRule ^(app|core) index.php [R=404,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|pub|favicon\.ico|robots\.txt|humans\.txt\|sitemap\.gz|sitemap\.xml)
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

<IfModule !mod_rewrite.c>
    # Prevent directory listings
    Options -Indexes

    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    #
    #   -> Remember to add the subdirectory if necessary.
    #
    ErrorDocument 404 /index.php
</IfModule>
10
  • Have you dumped $_FILES to see if it has the file? Commented Jun 12, 2013 at 19:12
  • VAR_DUMP() your $_FILES array to make sure that the file is actually being sent to your controller. Commented Jun 12, 2013 at 19:13
  • Which version of CodeIgniter? CI 2.1.1 fixed a bug with this symptom due to incorrect mime-type detection. ellislab.com/codeigniter/user-guide/changelog.html Commented Jun 12, 2013 at 19:14
  • i already checked, $_FILES is empty - it shows Array() Commented Jun 12, 2013 at 19:15
  • i have the last version Commented Jun 12, 2013 at 19:15

2 Answers 2

1

i hope this code is usefull to you

 <from .....>
      <input type="file" name='xyz'  />
 </form>

put your your file name in do_upload() function like...

  $this->upload->do_upload('xyz');

may be help you.....

Sign up to request clarification or add additional context in comments.

Comments

0

try that

<?php

class Upload extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
    }

    function index()
    {
        $this->load->view('upload_form', array('error' => ' ' ));
    }

    function do_upload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

        $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);
        }
    }
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.