为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Codeigniter zip 库压缩时出现阿拉伯语文件名问题

使用 Codeigniter zip 库压缩时出现阿拉伯语文件名问题

PHP
ITMISS 2022-10-09 17:29:01
我有某些文件要压缩,其中一些有阿拉伯名称,提取后,它们会损坏。我的 PHP 版本是 7.2.18,我使用的是 Codeigniter 3.1 框架。实际文件名:كلمة العينة.docx 压缩文件名:+â+ä+à+¬_+º+ä+¦+è+å+¬.docxpublic function generate_zip() {        $this->load->library('zip');        $zip_files = $this->document_model->get_documents();        foreach ($zip_files as $zip_file) {                 $this->zip->read_file('uploads/documents/' . $zip_file->document_file_name);        }        $this->zip->download('temp.zip');    }
查看完整描述

1 回答

?
饮歌长啸

TA贡献1951条经验 获得超3个赞

请尝试使用以下代码。


/* creates a compressed zip file */

function create_zip($files = array(),$destination = '',$overwrite = false) {

    //if the zip file already exists and overwrite is false, return false

    if(file_exists($destination) && !$overwrite) { return false; }

    //vars

    $valid_files = array();

    //if files were passed in...

    if(is_array($files)) {

        //cycle through each file

        foreach($files as $file) {

            //make sure the file exists

            if(file_exists($file)) {

                $valid_files[] = $file;

            }

        }

    }

    //if we have good files...

    if(count($valid_files)) {

        //create the archive

        $zip = new ZipArchive();

        if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {

            return false;

        }

        //add the files

        foreach($valid_files as $file) {

            $zip->addFile($file,$file);

        }

        //debug

        //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;


        //close the zip -- done!

        $zip->close();


        //check to make sure the file exists

        return file_exists($destination);

    }

    else

    {

        return false;

    }

}


$files_to_zip = array(

    'عينة.txt',

);

//if true, good; if false, zip creation failed

$result = create_zip($files_to_zip,'my-archive.zip');


查看完整回答
反对 回复 2022-10-09
  • 1 回答
  • 0 关注
  • 137 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号