2

我正在使用 codeigniter,当我尝试上传一些文本文件时发现了一个奇怪的情况。

使用指示(CI doc)的方法文档一切正常,但是如果我尝试上传包含字符串'//'(不带引号)的文件,我得到的结果是“不允许您尝试上传的文件类型。”

任何想法?

使用的代码:(控制器)

function do_upload() {
    $config['upload_path'] = APPPATH.'uploads/';
    $config['allowed_types'] = 'txt|csv';
    $config['max_size'] = '1024';
    $config['max_width']  = '0';
    $config['max_height']  = '0';
    $this->load->library('upload', $config);
    @var_dump($_FILES['userfile']);   // debug
    if (!$this->upload->do_upload()) {
        $error = array('error' => $this->upload->display_errors());
        $this->load->view('upload_form', $error);
    } else 
        echo "<br>upload ok";
}

upload_form.php(查看):

<?php 
    if (isset($error)) echo $error;
    echo form_open_multipart('supervisor/do_upload'); 
    echo form_label('File', 'userfile');
    echo form_upload('userfile');
    echo form_submit('submit', 'Upload');
    echo form_close() 
?>

例如:(.txt 用于上传)

[file1.txt]:
THIS IS A TEXT FILE     # work fine

[file2.txt]:
THIS IS A // TEXT FILE    # fail!  note: {blank}//{blank}

输出(上传file1.txt)

array(5) { ["name"]=> string(9) "file1.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpLVaMGs" ["error"]=> int(0) ["size"]=> int(19) }
upload ok

输出(上传file2.txt)

array(5) { ["name"]=> string(9) "file2.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpFu4znR" ["error"]=> int(0) ["size"]=> int(22) }

The filetype you are attempting to upload is not allowed.
...

Firebug POST:(上传file2.txt)

userfile    THIS IS A // TEXT FILE
submit  Upload
Fuente
-----------------------------15028408581691128039842883428 
Content-Disposition: form-data; name="userfile"; filename="file2.txt" 
Content-Type: text/plain 
THIS IS A // TEXT FILE 
-----------------------------15028408581691128039842883428 
Content-Disposition: form-data; name="submit" 
Upload 
-----------------------------15028408581691128039842883428--
4

1 回答 1

0

我多次遇到这个问题,我总是在使用新的系统文件夹时进行以下修复。这是一个 CI 错误。请让我知道它是否有效?

转到系统/库/Uploads.php——第 1059 行

@exec('file --brief --mime-type ' . escapeshellarg($file['tmp_path']), $output, $return_code);

变成:

@exec('file --brief --mime-type ' . escapeshellarg($file['tmp_name']), $output, $return_code);

现在看看第 1044-1045 行。它应该看起来像:

$this->file_type = @mime_content_type($file['tmp_name']);
return;

更改返回语句:

$this->file_type = @mime_content_type($file['tmp_name']);
if(strlen($this->file_type) > 0) return;
于 2013-03-22T05:56:32.307 回答