0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHP CodeIgniter ファイルをフォルダ分けしてZIP圧縮する

Last updated at Posted at 2017-02-13

タイトルの通りファイルをフォルダ分けしてZIP圧縮するロジックです。

zip_folder.php
public function zip_folder
{
  $this->load->library('zip');
  $img_folder_list = [
    'folder1' => ['http://img1.jpg', 'http://img2.jpg', 'http://img3.jpg'],
    'folder2' => ['http://img4.jpg', 'http://img5.jpg', 'http://img6.jpg'],
    'folder3' => ['http://img7.jpg', 'http://img8.jpg', 'http://img9.jpg'],
  ];

  foreach ($img_url_list as $folder_name => $img_url_list) {
    $this->zip->add_dir($folder_name);
    foreach ($img_url_list as $img_url) {
      $split_url = explode('/', $img_url);
      $this->zip->add_data($folder_name . '/' . $split_url[count($split_url) - 1], file_get_contents($img_url));
    }
  }
  $this->zip->archive('img_list.zip');
  $this->zip->download('img_list.zip');
}

今回はWeb上にある画像をフォルダに分けてZIPにしましたが、ローカルファイルでもそんなに変わらない処理になるでしょう。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?