Codeigniter 3 send file with extension PFX

Asked

Viewed 427 times

0

I need to upload a file with the extension .pfx (digital certificate).

I’m using the library Upload of CodeIgniter as follows: I’m putting the extension allowed_types but does not send. Returns: The file type you are trying to upload is not allowed.

$config['upload_path'] = $pasta;
$config['allowed_types'] = 'pfx';
$config['max_size'] = 100000;
$config['encrypt_name'] = TRUE;

$this - > load - > library('upload');
$this - > upload - > initialize($config);
if ($this - > upload - > do_upload('userfile')) {
    echo json_encode(array('image1' = > $this - > upload - > data('file_name'), 'file_ext' = > str_replace(".", "", $this - > upload - > data('file_ext')), 'error' = > 0, 'mensage' = > 'Arquivo enviado com sucesso.'));
} else {
    echo json_encode(array('mensage' = > $this - > upload - > display_errors(), 'error' = > 1));
}
  • 1

    make a var_dump in the $config and in the $_FILES please.

  • C: wamp64 www application controllers Upload.php:127: array (size=4) 'upload_path' => string 'C:/wamp64 /www/public/clients/lumer/certificate/' (length=48) 'allowed_types' => string 'pfx' (length=3) 'max_size' => int 100000 encrypt_name=> Boolean true

  • C: wamp64 www application controllers Upload.php:127: array (size=1) 'userfile' => array (size=5) 'name' => string 'LUMER_INFORMATICA_LTDA_ME10422724000187 . pfx' (length=43) 'type' => string 'application /octet-stream' (length=24) 'tmp_name' => string 'C: wamp64 tmp php6D29.tmp' (length=25) 'error' => int 0 'size' => int 9527

  • 1

    you initialized the settings? $this->upload->initialize($config);

  • yes I initialized that way

  • Make the change in the post please! :)

Show 1 more comment

2 answers

2

This error occurs because the framework is not finding this extension in the list of mime types, I mean, he doesn’t know what it is or how to handle a file .pfx. To solve, open up config/mimes.php of its application and add the following line at the end of array():

'pfx' => array('application/octet-stream'),

Source: Preferences; get_mimes(); Mime type of pfx.

  • I’ll do it, as soon as I do the tests put here if it worked

  • even putting the line in the mimes of the bug and does not upload the . pfx

  • I checked the correct type in the console log and edited the answer. Try again.

  • Tested it again?

  • tested, even though I did not send and tested on different servers, so I uploaded in php in using the upload library, more trying to solve this problem.

  • Strange. Here to me this kind of file appeared as application/octet-stream. After I changed config/mimes.php worked well. Remember that in addition to config/mimes.php you should also use $config['allowed_types'] = 'pfx'; in his controller.

  • yes I did that I’m also finding it very strange and if I change to jpg and send it sends, but I’ll check right and anything I return. :)

Show 2 more comments

0

In addition to updating your MIMES files, also use the header type application/x-pkcs12,

That is to say:

'pfx'   =>  array('application/octet-stream', 'application/x-pkcs12')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.