Php 代码点火器文件上载-无文件类型

Php 代码点火器文件上载-无文件类型,php,codeigniter,file-upload,Php,Codeigniter,File Upload,在过去的一个小时里,我一直在搜索CodeIgniter论坛,试图弄明白这一点: 我正在使用CodeIgniter为web应用程序编写一个文件上载处理程序。到目前为止,我有以下代码来处理上传: public function send() { $config = array( 'upload_path' => 'path/to/my/upload/directory', 'allowed_types' => 'pdf' )

在过去的一个小时里,我一直在搜索CodeIgniter论坛,试图弄明白这一点:

我正在使用CodeIgniter为web应用程序编写一个文件上载处理程序。到目前为止,我有以下代码来处理上传:

public function send() {        
    $config = array(
        'upload_path' => 'path/to/my/upload/directory',
        'allowed_types' => 'pdf'
    );

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

    $this->upload->do_upload('pdf_upload');

    echo "<pre>";
    print_r($this->upload->data());
    echo "</pre>";
    exit();
}

文件类型为空。这可能是什么原因造成的?我遗漏了什么?

我在一个相关但不重复的问题中找到了答案:

如果您使用的是Codeigniter 2.1.0版,则上传中存在错误 图书馆。查看更多信息 细节

基本上我所做的就是修改文件上传中的几行代码 类(位置:./system/libraries/Upload.php)

1) 修改行号1044

发件人:

$this->file_type = @mime_content_type($file['tmp_name']);
if (strlen($this->file_type) > 0) return; 
@exec('file --brief --mime-type ' . escapeshellarg($file['tmp_name']), $output, $return_code); 
为此:

@exec('file --brief --mime-type ' . escapeshellarg($file['tmp_path']), $output, $return_code);
2) 修改线号1058

发件人:

$this->file_type = @mime_content_type($file['tmp_name']);
if (strlen($this->file_type) > 0) return; 
@exec('file --brief --mime-type ' . escapeshellarg($file['tmp_name']), $output, $return_code); 
为此:

@exec('file --brief --mime-type ' . escapeshellarg($file['tmp_path']), $output, $return_code);
正如您可能看到的,第1058行尝试使用 不存在


你正在运行什么版本的CI?我看到你找到了答案。我本想提出另一个问题,但不确定它是否适用。是的,我不确定这是一个重复的问题。显然,dangermark(这个问题的提问者)在上传时得到了一个文件类型;我没有。幸运的是,他的问题的答案也是我的答案。:-)很高兴您修复了它,但是您应该扩展核心库,而不是直接编辑它。只需将您从core库编辑的方法复制到新的方法中,这样,如果您更新CI core,您的更改就不会中断。