0

I have a program that used to accept image from user. I changed it to accept PDF file instead as requested by our clients problem is it doesn't work.

I already changed my mimes.php configuration to this

'pdf'    =>    array('application/pdf', 'application/x-pdf', 'application/x-download','application/download','binary/octet-stream'),

Here is my CI code for saving uploaded file

$config = array(
'upload_path'   =>  'news',
'allowed_types' =>  'pdf',
'max_size'  =>  '10000000',
);
$this->load->library('upload', $config);
$this->upload->do_upload('userfile');
$data = $this->upload->data();
echo json_encode(array('data' => $data));

HTML

<form id="imgadd-form" method="post" accept-charset="utf-8" enctype="multipart/form-data">
   Upload :<br>
   <input type="file" name="userfile" id="userfile">
</form>

Jquery

function uploadfile()
{
$.ajaxFileUpload({
    url     :   'save_data/uploadfile/',
    secureuri   :   false ,
    fileElementId   :   'userfile' ,
    dataType    :   'json' ,
    success     :   function( data , status ) {
        if ( status != 'error' ){//&& data.data.is_image ) {
            sysAlert( 'File Successfully Uploaded' );
        }
        else
            sysAlert( 'Error Uploading' );
    }
});
}

EDIT: The file is being reported by jquery as uploaded successfully since it returns the JSON but whenever I check the directory, nothing is there. Weird thing though, I renamed the file extension to .TXT and uploaded that 3.5MB pdf file with a .txt extension and it uploaded successfully and is in the proper directory.

EDIT: var_dump of $_FILES

"array(1) {
  ["userfile"]=>
  array(5) {
    ["name"]=> string(8) "test.pdf"
    ["type"]=> string(24) "application/octet-stream"
    ["tmp_name"]=>string(24) "C:\xampp\tmp\phpF84F.tmp"
    ["error"]=>int(0)
    ["size"]=>int(3748991)
  }
}

echo $this->upload->display_errors();

<p>The filetype you are attempting to upload is not allowed.</p>

Update: Change 'max_size'

'max_size'      =>  '10000000',

CI Version is 2.1.2

MegaNairda
  • 829
  • 2
  • 14
  • 24

1 Answers1

1

Mimes.php

'pdf'   =>  array('application/pdf', 'application/x-download')

CI Code:

$config['upload_path']   = '$path'; 
                $config['allowed_types'] = 'pdf';   
                $config['max_size']      = '4096';      
                $config['overwrite']     =  TRUE;

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

                if (!$this->upload->do_upload("csv_file")) {
                      echo $this->upload->display_errors(); die();
                      $this->data['error'] = array('error' => $this->upload->display_errors());
                } else {
                    $upload_result = $this->upload->data(); 
                }
Denmark
  • 538
  • 2
  • 8
  • 26