Welcome Guest, Not a member yet? Register   Sign In
How to upload file ?
#1

[eluser]mahe11[/eluser]
Hi All,
By using codeIgniter user guide it work. But when i try it in my controller then it cant work. so tell me which things i forget.



Code:
public  function savenew(){                
                
                $config['upload_path'] = base_url().'uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '2048';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
                   echo "error... ";
                    $data['error']= array('error' => $this->upload->display_errors());
                    }
                    else
                        {
                        echo 'file upload....';
                        $data = array('upload_data' => $this->upload->data());
                        
                        }
                
            }

Plz help me......
#2

[eluser]Atharva[/eluser]
Try relative path
Code:
$config['upload_path'] = './uploads/';
#3

[eluser]mahe11[/eluser]
ya try it..
one time :
Code:
$config['upload_path'] = './uploads/';

and 2nd time :
Code:
$config['upload_path'] = base_url().'uploads/';

but not working :long:
#4

[eluser]Atharva[/eluser]
Make sure uploads folder is writable (0777). Also, what error you are getting?
#5

[eluser]mahe11[/eluser]
thanks it solve.
i want to upload any type of file means it may be MS-Office(.doc, .ppt, .xls) type file or image type(.jpg, .gif, .png) currently only uploading image type I change controller as

Code:
$config['upload_path'] = './uploads/';
$config['max_size']    = '0';
$config['remove_spaces']='TRUE';
$this->load->library('upload', $config);

is above correct or something wrong?
#6

[eluser]Atharva[/eluser]
You should set
Code:
$config['allowed_types'] = 'gif|jpg|png|doc|ppt|xls';

Also remove_spaces should be boolean and not string
Code:
$config['remove_spaces'] = TRUE;
#7

[eluser]mahe11[/eluser]
only images was upload, document(doc, ppt, xls) not uploading not working...... :long:
#8

[eluser]Atharva[/eluser]
Post your code here. Also, there is a known issue with uploader class for V 1.7.2, you can go through this thread
#9

[eluser]mahe11[/eluser]
Code:
public  function savenew(){                
                
         $config['upload_path'] = './uploads/';
         $config['allowed_types'] = 'gif|jpg|png|doc|ppt|xls';
         $config['max_size']    = '0';
         $config['remove_spaces']=TRUE;
        
         $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
                   echo "error... ";
                    $data['error']= array('error' => $this->upload->display_errors());
                    }
                    else
                        {
                        echo 'file upload....';
                        $data = array('upload_data' => $this->upload->data());
                        
                        }
                
            }

This is controller code.

Code:
<?php  echo form_open_multipart("attach/newfile", $attributes); ?>
<input class="text-input, formInputs" type="text" name="subject" id="subject" size="35" value=""/>
<input type="file" name="userfile" size="35" />
<input type="submit" name="Save" value="Save" class="submit">
<?php echo form_close();?>

this is html code
#10

[eluser]Atharva[/eluser]
You can replace your existing upload.php in system/libraries folder with CI 2.0 version from here You can use the 2.0 Upload.php in 1.7.2 without any problems.




Theme © iAndrew 2016 - Forum software by © MyBB