<legend id='SaA0X'><style id='SaA0X'><dir id='SaA0X'><q id='SaA0X'></q></dir></style></legend>
    <bdo id='SaA0X'></bdo><ul id='SaA0X'></ul>
    <tfoot id='SaA0X'></tfoot>
  • <small id='SaA0X'></small><noframes id='SaA0X'>

    <i id='SaA0X'><tr id='SaA0X'><dt id='SaA0X'><q id='SaA0X'><span id='SaA0X'><b id='SaA0X'><form id='SaA0X'><ins id='SaA0X'></ins><ul id='SaA0X'></ul><sub id='SaA0X'></sub></form><legend id='SaA0X'></legend><bdo id='SaA0X'><pre id='SaA0X'><center id='SaA0X'></center></pre></bdo></b><th id='SaA0X'></th></span></q></dt></tr></i><div id='SaA0X'><tfoot id='SaA0X'></tfoot><dl id='SaA0X'><fieldset id='SaA0X'></fieldset></dl></div>

      1. php创建没有zip文件路径的zip文件

        php creating zips without path to files inside the zip(php创建没有zip文件路径的zip文件)

              <tbody id='vxzIS'></tbody>

            <tfoot id='vxzIS'></tfoot>

              <bdo id='vxzIS'></bdo><ul id='vxzIS'></ul>
                1. <i id='vxzIS'><tr id='vxzIS'><dt id='vxzIS'><q id='vxzIS'><span id='vxzIS'><b id='vxzIS'><form id='vxzIS'><ins id='vxzIS'></ins><ul id='vxzIS'></ul><sub id='vxzIS'></sub></form><legend id='vxzIS'></legend><bdo id='vxzIS'><pre id='vxzIS'><center id='vxzIS'></center></pre></bdo></b><th id='vxzIS'></th></span></q></dt></tr></i><div id='vxzIS'><tfoot id='vxzIS'></tfoot><dl id='vxzIS'><fieldset id='vxzIS'></fieldset></dl></div>
                  <legend id='vxzIS'><style id='vxzIS'><dir id='vxzIS'><q id='vxzIS'></q></dir></style></legend>
                2. <small id='vxzIS'></small><noframes id='vxzIS'>

                  本文介绍了php创建没有zip文件路径的zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 php 创建一个 zip 文件(它确实这样做了 - 取自此页面 - http://davidwalsh.name/create-zip-php),但是在 zip 文件中包含文件本身的所有文件夹名称.

                  I'm trying to use php to create a zip file (which it does - taken from this page - http://davidwalsh.name/create-zip-php), however inside the zip file are all of the folder names to the file itself.

                  是否可以只将 zip 中的文件减去所有文件夹?

                  Is it possible to just have the file inside the zip minus all the folders?

                  这是我的代码:

                  function create_zip($files = array(), $destination = '', $overwrite = true) {
                  
                      if(file_exists($destination) && !$overwrite) { return false; };
                      $valid_files = array();
                      if(is_array($files)) {
                          foreach($files as $file) { 
                              if(file_exists($file)) { 
                                  $valid_files[] = $file;
                              };
                          };
                      };
                      if(count($valid_files)) { 
                          $zip = new ZipArchive();
                          if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { 
                              return false;
                          };
                          foreach($valid_files as $file) { 
                              $zip->addFile($file,$file);
                          };
                          $zip->close();
                          return file_exists($destination);
                      } else {
                          return false;
                      };
                  
                  };
                  
                  
                  $files_to_zip = array('/media/138/file_01.jpg','/media/138/file_01.jpg','/media/138/file_01.jpg');
                  
                  $result = create_zip($files_to_zip,'/...full_site_path.../downloads/138/138_files.zip');
                  

                  推荐答案

                  这里的问题是 $zip->addFile 被传递了相同的两个参数.

                  The problem here is that $zip->addFile is being passed the same two parameters.

                  根据文档:

                  bool ZipArchive::addFile ( string $filename [, string $localname ] )

                  bool ZipArchive::addFile ( string $filename [, string $localname ] )

                  文件名
                  要添加的文件的路径.

                  filename
                  The path to the file to add.

                  本地名称
                  ZIP 存档中的本地名称.

                  localname
                  local name inside ZIP archive.

                  这意味着第一个参数是文件系统中实际文件的路径,第二个是路径 &文件将在存档中的文件名.

                  This means that the first parameter is the path to the actual file in the filesystem and the second is the path & filename that the file will have in the archive.

                  当您提供第二个参数时,您需要在将其添加到 zip 存档时从中删除路径.例如,在基于 Unix 的系统上,这看起来像:

                  When you supply the second parameter, you'll want to strip the path from it when adding it to the zip archive. For example, on Unix-based systems this would look like:

                  $new_filename = substr($file,strrpos($file,'/') + 1);
                  $zip->addFile($file,$new_filename);
                  

                  这篇关于php创建没有zip文件路径的zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  1. <i id='nsAMV'><tr id='nsAMV'><dt id='nsAMV'><q id='nsAMV'><span id='nsAMV'><b id='nsAMV'><form id='nsAMV'><ins id='nsAMV'></ins><ul id='nsAMV'></ul><sub id='nsAMV'></sub></form><legend id='nsAMV'></legend><bdo id='nsAMV'><pre id='nsAMV'><center id='nsAMV'></center></pre></bdo></b><th id='nsAMV'></th></span></q></dt></tr></i><div id='nsAMV'><tfoot id='nsAMV'></tfoot><dl id='nsAMV'><fieldset id='nsAMV'></fieldset></dl></div>
                      <tbody id='nsAMV'></tbody>

                    <small id='nsAMV'></small><noframes id='nsAMV'>

                          <bdo id='nsAMV'></bdo><ul id='nsAMV'></ul>

                          <legend id='nsAMV'><style id='nsAMV'><dir id='nsAMV'><q id='nsAMV'></q></dir></style></legend>
                          1. <tfoot id='nsAMV'></tfoot>