Welcome Guest, Not a member yet? Register   Sign In
[Upload Class] Problem using custom file extension
#11

[eluser]BrianDHall[/eluser]
OK, here you go. Fully working code!

Change upload path to your folder, make sure permissions are correct (755 I think works) and ensure it is permitted for access in your .htaccess file.

Function for your controller
Code:
function upload_file()
    {
        $config = array(
        'upload_path' => './uploads',
        'allowed_types' => 'uvc',
        'overwrite' => false,
        'encrypt_name' => true,
        'remove_spaces' => true,
        'max_size' => 500);

        $this->load->library('upload', $config);

        if ($this->input->post('upload'))
        {
            $result = $this->upload->do_upload();

            $data = $this->upload->data();

            if ($result)
            {
                echo "It worked!\n";
                var_dump($data);
            }
        }

        $this->content = $this->load->view('fileuploadform');

    }

View:

Code:
<h3>Upload an Image</h3>

&lt;?=form_open_multipart('upload_file')?&gt;
&lt;?=$this->upload->display_errors()?&gt;
&lt;?=form_upload('userfile')?&gt;
&lt;?=form_submit('upload', 'Upload')?&gt;
&lt;?=form_close()?&gt;

Open mimes.php in config folder, should have something like:

Code:
$mimes = array(    'hqx'    =>    'application/mac-binhex40',
                'cpt'    =>    'application/mac-compactpro',
                'uvc'    =>    'text/plain',
...

If you still get file unallowed backup your mimes file and replace whole file with:

Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| MIME TYPES
| -------------------------------------------------------------------
| This file contains an array of mime types.  It is used by the
| Upload class to help identify allowed file types.
|
*/

$mimes = array('uvc' => 'text/plain');


/* End of file mimes.php */
/* Location: ./system/application/config/mimes.php */

This works great on my system, so if not working be sure to put this in a fresh controller, perhaps on a fresh version of CI - because this should work just fine!

Let me know if you get it working!


Messages In This Thread
[Upload Class] Problem using custom file extension - by El Forum - 09-08-2009, 02:24 PM
[Upload Class] Problem using custom file extension - by El Forum - 09-09-2009, 08:25 AM
[Upload Class] Problem using custom file extension - by El Forum - 09-09-2009, 10:13 AM
[Upload Class] Problem using custom file extension - by El Forum - 09-09-2009, 10:57 AM
[Upload Class] Problem using custom file extension - by El Forum - 09-09-2009, 11:45 AM
[Upload Class] Problem using custom file extension - by El Forum - 09-10-2009, 03:24 PM
[Upload Class] Problem using custom file extension - by El Forum - 09-10-2009, 06:49 PM
[Upload Class] Problem using custom file extension - by El Forum - 09-10-2009, 07:33 PM
[Upload Class] Problem using custom file extension - by El Forum - 09-10-2009, 08:00 PM
[Upload Class] Problem using custom file extension - by El Forum - 09-10-2009, 11:25 PM
[Upload Class] Problem using custom file extension - by El Forum - 09-11-2009, 07:55 AM
[Upload Class] Problem using custom file extension - by El Forum - 09-14-2009, 10:02 AM
[Upload Class] Problem using custom file extension - by El Forum - 09-14-2009, 10:42 AM
[Upload Class] Problem using custom file extension - by El Forum - 09-14-2009, 05:30 PM
[Upload Class] Problem using custom file extension - by El Forum - 09-14-2009, 11:52 PM



Theme © iAndrew 2016 - Forum software by © MyBB