Like "Zipar" files or directories in codeigniter

Asked

Viewed 177 times

1

I’ve seen it in the documentation, but they speak very plainly, and the understanding is not good. So can anyone explain to me in a more practical way how I can zip files in codeigniter? thanks.

Link to the documentation: https://www.codeigniter.com/user_guide/libraries/zip.html

I didn’t understand almost anything about the zipping process.

  • 1

    It will be interesting for you to [Dit] the question and add the link to the documentation by placing the code examples it presents here, describing what you have not extended.

1 answer

3


I’ll try to explain what’s in the documentation:

1 - You must load lib zip in your controller.

$this->load->library('zip');

2 - You declare the values you will use

$filepath = 'mydata1.txt'; // Diretório do Arquivo
$data = 'A Data String!'; // Conteúdo do Arquivo

3 - You will use the method: add_data

$this->zip->add_data( $filepath, $data ); // Essa função vai receber 2 parâmetros, o primeiro é o caminho do arquivo e o segundo é o conteúdo desse arquivo.

Now if you already have the file somewhere on your server, you will use the function below:

$this->zip->archive( $path, $archive_filepath ); // Primeiro parâmetro você vai passar o caminho do arquivo, o segundo é opcional caso queira que o zip tenha outro nome ou salvar em outro local.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.