小编Abd*_*sit的帖子

压缩目录中的所有文件并强制下载

我在我的网站上运行以下代码.我遇到的唯一问题是它在服务器上创建一个zip文件然后用户下载.

我想知道我应该怎么做才能在运行中生成zip文件而不首先将其转储到服务器磁盘上.我还想让用户暂停/恢复下载.

//function for zip
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
  //create the object
  $zip = new ZipArchive();
  //create the file and throw the error if unsuccessful
  if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
    exit("cannot open <$archive_file_name>\n");
  }

  //add each files of $file_name array to archive
  foreach($file_names as $files)
  {


  $zip->addFile($file_path.str_replace('./','',$files),translit($files).".mp3");
  }
  $zip->close();

  //then send the headers to foce download the zip file
  header("Content-type: application/zip");
  header("Content-Disposition: attachment; filename=$archive_file_name");
  header("Pragma: no-cache");
  header("Expires: 0");
  readfile("$archive_file_name");
  exit;
}
Run Code Online (Sandbox Code Playgroud)

php zip

6
推荐指数
1
解决办法
7711
查看次数

excel如何读取XML文件?

我已经研究了很多将xml文件转换为2d数组的方法与excel在excel中打开xml文件时尝试制作与excel相同的算法.

<items>
    <item>
        <sku>abc 1</sku>
        <title>a book 1</title>
        <price>42 1</price>
        <attributes>
            <attribute>
                <name>Number of pages 1</name>
                <value>123 1</value>
            </attribute>
            <attribute>
                <name>Author 1</name>
                <value>Rob dude 1</value>
            </attribute>
        </attributes>
        <contributors>
            <contributor>John 1</contributor>
            <contributor>Ryan 1</contributor>
        </contributors>
        <isbn>12345</isbn>
    </item>
    <item>
        <sku>abc 2</sku>
        <title>a book 2</title>
        <price>42 2</price>
        <attributes>
            <attribute>
                <name>Number of pages 2</name>
                <value>123 2</value>
            </attribute>
            <attribute>
                <name>Author 2</name>
                <value>Rob dude 2</value>
            </attribute>
        </attributes>
        <contributors>
            <contributor>John 2</contributor>
            <contributor>Ryan 2</contributor>
        </contributors>
        <isbn>6789</isbn>
     </item>
</items>
Run Code Online (Sandbox Code Playgroud)

我希望它将其转换为二维数组,就像在Excel中打开相同的文件一样,它会向您显示这样的内容

在此输入图像描述


我想像Excel那样转换为二维数组.到目前为止,我可以像Excel一样提取标签

function getColNames($array) {
    $cols   = array();
    foreach($array as $key=>$val) …
Run Code Online (Sandbox Code Playgroud)

php xml excel

6
推荐指数
1
解决办法
563
查看次数

标签 统计

php ×2

excel ×1

xml ×1

zip ×1