如何在使用Cakephp上传文件时将编码文件从ANSI更改为UTF-8?

gblwokeq  于 2022-11-11  发布在  PHP
关注(0)|答案(1)|浏览(133)

我有一个ANSI编码的CSV文件,当我将文件上传到服务器时,我需要将编码更改为UTF-8。
我正在使用cakephp 2.x我需要这个正确的逐行读取我的csv文件。

function import() {
    if ($this->request->is('post') || $this->request->is('put')) {
        $file = $this->request->data['Document']['submittedfile'];

        // NOW CHANGE ENCODING - but how ?
        // $this->pdfadd1->save($this->request->data);$filename = TMP . 'uploads' . DS . 'Address' . DS . $filename;

        move_uploaded_file($this->data['Document']['submittedfile']['tmp_name'],     TMP . 'uploads' . DS . 'Good' . DS . "towary.csv");
        $messages = $this->Good->import("towary.csv");
        $this->set('messages', $messages);
    }
nnt7mjpx

nnt7mjpx1#

试试看:

$encodedOutput = mb_convert_encoding($file, 'Windows-1252', 'UTF-8');

参照此answer
ANSI编码是一个稍显通用的术语,用于指代系统(通常是Windows)上的标准代码页。它更适合被称为Windows-1252(至少在西方/美国系统上,它可以代表其他系统上的某些其他Windows代码页)。

相关问题