Проблема с именами файлов Arabi c при сжатии с помощью zip-библиотеки Codeigniter - PullRequest
1 голос
/ 25 февраля 2020

У меня есть определенные файлы для сжатия, и некоторые из них имеют арабские c имена. При извлечении они выходят поврежденными. Моя PHP версия - 7.2.18, и я использую платформу Codeigniter 3.1.

Фактическое имя файла: كلمة العينة. Docx Сжатое имя файла: + â + ä + à + ¬_ + º + ä + ¦ + è + å + ¬.docx

public 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 Ответ

0 голосов
/ 25 февраля 2020

Привет Пожалуйста, попробуйте с кодом ниже.

/* 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');
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...