在codeigniter

时间:2016-05-20 10:08:12

标签: php codeigniter

我使用

在codeigniter上传文件
$this->upload->do_upload('image')

但是当文件移动到特定路径时,文件扩展名会被更改(它已更改为小写)

例如,如果我上传文件" profile.JPG"它改变了" profile.jpg"

2 个答案:

答案 0 :(得分:2)

请更改CI系统库

CI上传库中的默认值$ file_ext_tolower = FALSE。

。系统\库\ upload.php的

override public func setSelected(selected: Bool) {
    super.setSelected(selected)
    // Do your customization here

    // changing text color
    self.textLabel?.textColor = selected ? UIColor.blueColor() : UIColor.blackColor()
}

答案 1 :(得分:1)

do_upload执行此操作

$ config ['allowed_types'] ='gif | jpg | png'

function do_upload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

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

        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());

            $this->load->view('upload_form', $error);
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());

            $this->load->view('upload_success', $data);
        }
    }

如果您想使用相同的名称/扩展名,请发送以保存文件。您可以使用:

$upload_dir= $this->config->item("upload_dir");
$fileName =  $_POST['sku_code'].".".$extension;
$filePath = $upload_dir.$fileName;
move_uploaded_file($_FILES["image-file"]["tmp_name"],$filePath );

有用的链接:

https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html