Welcome Guest, Not a member yet? Register   Sign In
need upload help
#1

[eluser]tjstalcup[/eluser]
I wish there was such a thing as a CI consultant that I could pay for help Sad

I am new to CI, and i'm trying to do a simple image upload however I keep getting the error You did not select a file to upload.



here is my code:


controller:
Code:
function create_imprint()
    {
        $config['upload_path'] = './uploads/';
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            $data['error'] = array('error' => $this->upload->display_errors());
            
            $product_id = $this->uri->segment(3);
            $this->load->model('Imprint');
            
            $this->db->where('id',$product_id);
            $query =  $this->db->get('products');
            $row = $query->row();
            
            $data['title'] = "NAVA New $row->name";
            $data['productname'] = $row->name;
            $data['query'] = $this->Imprint->get_fields($product_id);
            
            $this->load->view('header',$data);
            $this->load->view('products/new_imprint_view',$data);
            
        }    
        else
        {
            $data = array('upload_data' => $this->upload->data());
            
            $this->load->model('Imprint');
            //$query = $this->Imprint->new_data($_POST);
            
            $data['title'] = "NAVA New Brochure";
            $this->load->view('header', $data);
            $this->load->view('products/create_imprint_view',$data);
        }
    }

view

Code:
<h2>New &lt;?=$productname?&gt;</h2>
<p><b>&lt;?=$error['error']?&gt;</b></p>

<p>&lt;?=anchor('products/imprint/'.$this->uri->segment(3),'Back to '.$productname.' Data List');?&gt;</p>

&lt;?=form_open_multipart('products/create_imprint/'.$this->uri->segment(3));?&gt;
<table border="0" cellpadding="5" cellspacing="5">
&lt;?php foreach($query->result() as $row): ?&gt;
<tr>

    <td align="right" valign="top"><label for="&lt;?=$row->name?&gt;" title="&lt;?=$row->tooltip?&gt;">&lt;?=$row->label?&gt;:</label></td>

    &lt;?php if($row->type=="textarea"): ?&gt;
    <td>&lt;textarea rows="20" cols="40" name="&lt;?=$row-&gt;name?&gt;" id="&lt;?=$row->name?&gt;" title="&lt;?=$row->tooltip?&gt;">&lt;/textarea&gt;&lt;/td>
    &lt;?php elseif($row->type=="image"): ?&gt;
    <td>&lt;input type="file" name="&lt;?=$row-&gt;name?&gt;" id="&lt;?=$row->name?&gt;" title="&lt;?=$row->tooltip?&gt;" size="20" /></td>
    &lt;?php endif; ?&gt;
</tr>
&lt;?php endforeach; ?&gt;

<tr>
    <td>&nbsp;</td>
    <td>&lt;input type="submit" value="Create Artwork" /&gt;&lt;/td>
</tr>
</table>
&lt;/form&gt;
#2

[eluser]gtech[/eluser]
your input type file needs to be named "userfile" unless you pass a string to do_upload()

Code:
&lt;input type="file" name="userfile"&gt;


if you look at the CI code in the libraries directory in upload.php you can see the code that is doing it:
Code:
/**
     * Perform the file upload
     *
     * @access    public
     * @return    bool
     */    
    function do_upload($field = 'userfile')
    {
        // Is $_FILES[$field] set? If not, no reason to continue.
        if ( ! isset($_FILES[$field]))
        {
            $this->set_error('upload_no_file_selected');
            return FALSE;
        }
#3

[eluser]tjstalcup[/eluser]
perfect thanks!
#4

[eluser]gtech[/eluser]
no probs glad to help occasionally Smile, if in doubt don't be scared to read the code.. as its quite well written and easy to follow.




Theme © iAndrew 2016 - Forum software by © MyBB