Search code examples
phpcodeigniterfile-uploadcodeigniter-3

I want to pass o/p of following line into controller ie <?php echo $module[$i]->im_name; ?>


This is my code :

if (count($template) >=1) { ?>  

    <div class="mdl-cell mdl-cell--4-col" id="select">
        <div class="mdl-card mdl-shadow--4dp">
            <div class="mdl-card__title">
                <h2 class="mdl-card__title-text">select <?php echo $module[$i]->im_name; ?> Template</h2>
              </div>
            <div class="mdl-card__media">
                <?php echo $template[0]->iut_tempname; ?>

            </div>

            <a href="<?php echo base_url("Account/template_list/"); ?>" class="btn btn-info btn-lg">
                    <span class="glyphicon glyphicon-cog"></span>
            </a>

        </div>
    </div>  

    <?php

        }

I want to pass o/p of this im_name; ?> to controller .


Solution

  • Hope this will help you :

    Create a folder uploads in your views folder and use VIEWPATH for the upload_path like this :

    $config['upload_path']  = VIEWPATH.'uploads/'; 
    

    Your code should be like this :

    if (isset($_FILES["image_file"]["name"])) 
    {
    
        $config['upload_path']  = VIEWPATH.'uploads/'; 
        $config['allowed_types']= 'txt|php|html';
    
        $this->load->library('upload', $config);
        $this->upload->initialize($config);
    
        if (!$this->upload->do_upload('image_file')) 
        {
            echo $this->upload->display_errors();
        }
        else
        {
            $data = $this->upload->data();
            echo '<img src="'.base_url().'uploads/'.$data["file_name"].'" />';  
        }
    }
    

    For more : https://www.codeigniter.com/user_guide/general/reserved_names.html