Welcome Guest, Not a member yet? Register   Sign In
Upload File Bug
#11

[eluser]B3ll4triX[/eluser]
Fatal error: Call to undefined function finfo_open() in /home/xeenit/public_html/UQYG.com/system/libraries/Upload.php on line 195
#12

[eluser]Dregond Rahl[/eluser]
[quote author="B3ll4triX" date="1242897630"]Fatal error: Call to undefined function finfo_open() in /home/xeenit/public_html/UQYG.com/system/libraries/Upload.php on line 195[/quote]

sorry was editing something. try now =]
#13

[eluser]B3ll4triX[/eluser]
sorry, the problem is not in upload library, but i wrong in use download helper...
thanks for apply...
#14

[eluser]Cheater[/eluser]
Ideally the upload library should use FileInfo to validate all files where avaliable.
Right now it only validates images with getimagesize.

Remember: The MIME type that the upload library gets is supplied by the browser - its accuracy is not guaranteed and you can not rely on it.
People having problems with pdf files, that is why your having trouble.
#15

[eluser]Josepzin[/eluser]
I have modified the PDF type definition in aplication/config/mimes.php

Code:
'pdf' => array('application/pdf', 'application/x-download', 'application/download'),
#16

[eluser]Dregond Rahl[/eluser]
[quote author="Josepzin" date="1242906247"]I have modified the PDF type definition in aplication/config/mimes.php

Code:
'pdf' => array('application/pdf', 'application/x-download', 'application/download'),
[/quote]

you need to add

Code:
application/octet

because that's what is being sent, and being a problem.
#17

[eluser]Cheater[/eluser]
[quote author="Dregond Rahl" date="1242907815"]you need to add

Code:
application/octet

because that's what is being sent, and being a problem.[/quote]
Err Dont you mean application/octet-stream?
#18

[eluser]Dregond Rahl[/eluser]
yup

application/octet-stream

i copied it wrong XD
#19

[eluser]Unknown[/eluser]
Hopefully this helps. I tried every variation of the posts to try to get CI to accept PDF, INDD, AI, ZIP files and more. Messing with the mime types did not seem to help. I found a fix to add to the Upload.php file within the is_allowed_filetype function.

The problem seems to be within the foreach loop. I don't claim to be a good programmer, but I think the fact that within every condition in this loop, there is a return true or return false which breaks the loop?? (feel free to correct me if I am wrong)

Here is my updated code:
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;
        }

        $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');
        
        /*
            Experienced errors with file types
            PDF     = application/pdf
            ZIP     = application/octet-stream
            INDD    = application/octet-stream
            ZIP     = application/zip
            AI      = application/postscript
        */
        $error_types = array(
                            'application/pdf',
                            'application/octet-stream',
                            'application/zip',
                            'application/postscript'
                            );
        
        foreach ($this->allowed_types as $val)
        {
            $mime = $this->mimes_types(strtolower($val));
                        
            // Images get some additional checks
            if (in_array($val, $image_types))
            {
                
                if (getimagesize($this->file_temp) === FALSE)
                {                    
                    // Added this condition for the error types
                    if (in_array($this->file_type, $error_types, TRUE))
                    {
                        return TRUE;
                    }
                    else
                    {
                        return FALSE;
                    }
                }
            }
            
            if (is_array($mime))
            {
                if (in_array($this->file_type, $mime, TRUE))
                {
                    return TRUE;
                }
            }
            else
            {
                if ($mime == $this->file_type)
                {
                    return TRUE;
                }    
            }        
        }
        
        return FALSE;
    }

If you add the file types you are experiencing errors with in that $error_types array, then the upload function works with those files you experience issues with where the mime type does not fix.

I hope this helps others who had the same issues as me.
#20

[eluser]Josepzin[/eluser]
I quoted my very, very simple solution, really, is simple and easy, without make changes to the /system code.

Is necessary only one line of code before upload the file, it search the extension of the selected file to upload in the allowed types:
Code:
$config['allowed_types'] = substr(
    $allowed_types,
    strpos($allowed_types, substr($_FILES['userfile']['name'], -3)), 3);


Example:
Code:
$allowed_types = 'pdf|doc|jpg|zip|png|gif'; // <--- your allowed types

// This is my fix
$config['allowed_types'] = substr($allowed_types, strpos($allowed_types, substr($_FILES['userfile']['name'], -3)), 3);

// load library and config params
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{...

The result of this code is:
Quote:With $_FILES['userfile']['name'] = 'document.pdf';
$config['allowed_types'] = 'pdf';
Ok, upload it!

Or:
Quote:With $_FILES['userfile']['name'] = 'image.jpg';
$config['allowed_types'] = 'jpg';
Ok, upload it!

Another with incorrect type:
Quote:With $_FILES['userfile']['name'] = 'terrible_mortal_virus.exe';
$config['allowed_types'] = 'pdf'; // <--- The first extension of $allowed_types
Error, type not allowed.




Theme © iAndrew 2016 - Forum software by © MyBB