0

我有一个用于接受用户图像的程序。我按照客户的要求将其更改为接受 PDF 文件,问题是它不起作用。

我已经将 mimes.php 配置更改为此

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

这是我用于保存上传文件的 CI 代码

$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' );
    }
});
}

编辑: jquery 报告该文件已成功上传,因为它返回 JSON,但每当我检查目录时,什么都没有。奇怪的是,我将文件扩展名重命名为 .TXT 并上传了 .txt 扩展名的 3.5MB pdf 文件,它成功上传并位于正确的目录中。

编辑:$_FILES 的 var_dump

"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>

更新:更改“max_size”

'max_size'      =>  '10000000',

CI 版本为 2.1.2

4

1 回答 1

1

哑剧.php

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

CI 代码:

$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(); 
                }
于 2013-10-11T02:55:51.327 回答