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
The filetype you are attempting to upload is not allowed.
* – MegaNairda Nov 13 '12 at 11:25