Welcome Guest, Not a member yet? Register   Sign In
Frustrated - Upload problem!
#1

[eluser]Lazos[/eluser]
I have this code. It was working just fine. I am sure I did not touch anything but when I completed my application something happened. No more uploading...

I am getting this error "The filetype you are attempting to upload is not allowed."

I went to the upload file and I print_r the mimes and the file type I am sending to the upload class is the correct one.

The result of print_r($mime) is:
Array ( [0] => application/x-zip [1] => application/zip [2] => application/x-zip-compressed )

The result of print_r($this->file_type) is:
\"application/x-zip\"

I do not know if is normal to have the \"\" around it...

Somebody PLEASE HELP I WASTED 4 hours for these and still I do not know why suddenly it stopped working Sad.

Check FileType Function of Upload Class
Code:
function is_allowed_filetype()
    {
        if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
        {
            $this->set_error('upload_no_file_types');
            return FALSE;
        }
                
        foreach ($this->allowed_types as $val)
        {
            $mime = $this->mimes_types(strtolower($val));
        
            if (is_array($mime))
            {
                if (in_array($this->file_type, $mime, TRUE))
                {
                    return TRUE;
                }
            }
            else
            {
                if ($mime == $this->file_type)
                {
                    return TRUE;
                }    
            }        
        }
        
        return FALSE;
    }

Import File Controller
Code:
function import() {
        $field_name = 'userfile';
        echo $_FILES[$field_name]['type'];
        $config['upload_path'] = 'D:/websites/dissertation/application/views/templates/';
        $config['max_size'] = '2000';
        $config['allowed_types'] = 'zip';
        $config['overwrite'] = true;
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload($field_name))
        {
            $error = array('error' => $this->upload->display_errors());
            print_r($error);
            if(!empty($error)) {
                redirect('/index.php/admin/thememanager?error=true&errormsg=error_uploading', 'location', 301);    
            }                                
        }    
        else
        {
            $data = $this->upload->data();
        }
        
    }

Form View
Code:
<form id="themeform2" method="post" action="{V_ACTION}" enctype="multipart/form-data">
                <div class="pageoverflow">
                    <p class="pagetext">Upload Theme</p>
                    <p class="pageinput">&lt;input type="file" name="userfile" size="50" maxlength="255" /&gt;&lt;/p>
                </div>
                <div class="pageoverflow">
                    <p class="pagetext">&nbsp;</p>
                    <p class="pageinput">&lt;input name="submit" value="Import" type="submit" /&gt;&lt;/p>
                </div>
            &lt;/form&gt;
#2

[eluser]abmcr[/eluser]
See in the config/mimes.php and see if the type of zip is correct
#3

[eluser]Lazos[/eluser]
Well I do not know what happened... I restarted my PC and everything is working again. I think maybe Apache or PHP went haywire or something. I wasted so many hours and the problem was not inside CI Sad.




Theme © iAndrew 2016 - Forum software by © MyBB