CodeIgniter Forums
File Upload class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: File Upload class (/thread-25288.html)



File Upload class - El Forum - 12-07-2009

[eluser]The Casual Bot[/eluser]
Hey everyone

iv had a look round Google and the Ci forum but cant find the help i need

my uploads currently workd for .bmp .jpeg .jpg & .png (the default ones in the user guide)

but when i added pdf|doc|xls|xlsx|tiff|docx

i can upload any of these files but the original ones still work

heres a section my controller

Code:
function do_upload()
    {
                print_r($_FILES);
                $map = directory_map('./files/');
                if (!isset($map[$this->uri->segment(3)])) {
                $this->ftp->connect();
                $this->ftp->mkdir('/public_html/files/'.$this->uri->segment(3), DIR_WRITE_MODE);  
                }
        $config['upload_path'] = './files/'.$this->uri->segment(3);
        $config['allowed_types'] = 'docx|gif|jpg|png|pdf|doc|xls|xlsx|tiff|jpeg';
        $config['max_size']    = '2048';
        $config['max_width']  = '0';
        $config['max_height']  = '0';
                $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload())
        {


             $this->load->model('Viewappmodel');
                     $data['data'] = $this->Viewappmodel->full($this->uri->segment(3));                  
        
                     $data['data']['message'] = $this->upload->display_errors('<p class="msg error">', '</p>');
                     $this->load->view('header_view');
                     $this->load->view('sidebar_view');
                     $this->load->view('viewapp', $data);
                     $this->load->view('footer_view');
        }
        else
        {

                    
                     $this->load->model('Viewappmodel');
                     $data['data'] = $this->Viewappmodel->full($this->uri->segment(3));
                    
                    

                     $file = $this->upload->data();
                     $data['data']['message'] = '<p class="msg done">File Uploaded ( '.$file['file_name'].' )</p>';

                     $this->load->view('header_view');
                     $this->load->view('sidebar_view');
                     $this->load->view('viewapp', $data);
                     $this->load->view('footer_view');
        }
    }

from some advice i got from the forum im printing out $_FILES and it contains the following

Code:
Array ( [userfile] => Array ( [name] => 123456789.pdf [type] => application/pdf [tmp_name] => /tmp/phpMXeoUT [error] => 0 [size] => 340655 ) )

the error returned by the upload class is

Code:
The filetype you are attempting to upload is not allowed.

and my form is

Code:
&lt;?php echo form_open_multipart('viewapp/do_upload/'.$data['application_id']);?&gt;

&lt;input type="file" name="userfile" size="20" /&gt;

<br /><br />

&lt;input type="submit" value="upload" /&gt;

&lt;/form&gt;

thanks in advance for you help Smile


File Upload class - El Forum - 12-07-2009

[eluser]JamieBarton[/eluser]
I know the error you getting doesn't suggest it, but have you tried having a look at your php.ini file for max upload size? It could be feeding an error from that, I can't see a clear error in your controller.


File Upload class - El Forum - 12-07-2009

[eluser]The Casual Bot[/eluser]
phpinfo says

Code:
upload_max_filesize    2M    2M

and my code

Code:
$config['max_size']    = '2048';

and they user guide

Code:
The maximum size (in kilobytes) that the file can be. Set to zero for no limit. Note: Most PHP installations have their own limit, as specified in the php.ini file. Usually 2 MB (or 2048 KB) by default.

so they all = the same

and the file im upload is only 332kb


File Upload class - El Forum - 12-07-2009

[eluser]The Casual Bot[/eluser]
arrh fixed it
theres a bug in the upload.php


Code:
// Images get some additional checks
if (in_array($val, $image_types))

but $val is not the file extension

so by change the order of allowed file types it now works

ie

Code:
$config['allowed_types'] = 'docx|pdf|doc|xls|xlsx|tiff|jpeg|gif|jpg|png';



File Upload class - El Forum - 12-17-2009

[eluser]bikuta[/eluser]
Sorry to reopen this thread, but do we need to update the php.ini even though we've updated the $config['max_size'] value?


File Upload class - El Forum - 12-17-2009

[eluser]Michael Ditto[/eluser]
[quote author="bikuta" date="1261081200"]Sorry to reopen this thread, but do we need to update the php.ini even though we've updated the $config['max_size'] value?[/quote]

If you've made $config['max_size'] larger than the value in php.ini, then yes.