代码之家  ›  专栏  ›  技术社区  ›  markzzz

php-pclzip.lib故障

  •  0
  • markzzz  · 技术社区  · 14 年前

    不知道是否有人使用此库生成(服务器端)zip文件。在这里您可以看到我的代码:

    $i=0;
    while ($row = mysql_fetch_array($query, MYSQL_NUM)) {
        $title[$i]=$row[1]." - ".$row[2];
    
        // i remove some chars, because they can create confusion with the filesystem
        $titleontxt=$title[$i];
        $title[$i]=str_replace("/", "", $title[$i]);
        $title[$i]=str_replace(":", "", $title[$i]);
        $title[$i]=str_replace("*", "", $title[$i]);      
        $title[$i]=str_replace("?", "", $title[$i]);      
        $title[$i]=str_replace('"', "", $title[$i]);
        $title[$i]=str_replace("<", "", $title[$i]);
        $title[$i]=str_replace(">", "", $title[$i]);
        $title[$i]=str_replace("|", "", $title[$i]);                  
        $title[$i]=str_replace(",", "", $title[$i]);
    
        $trackid=$row[0];
        mkdir("./temp/".$_SESSION['nickname'], 0700);
        $file = fopen("./temp/".$_SESSION['nickname']."/".$title[$i].".txt", "w");
        $fwrite = fwrite($file, $titleontxt."\r\n");
    
        $j=0;
        $fwrite = fwrite($file, "\r\n single side");
        $fwrite = fwrite($file, "\r\n there is a single line");
    
    
        fclose($file);
        $i++;
    }
    
    include_once("./lib/pclzip.lib.php");
    $data=date("Y-m-d");
    $zipstring="./temp/".$_SESSION['nickname']."/".$trackid."-GTW-Tracklist.zip";
    $filezip=new PclZip($zipstring);
    
    for($i=0; $i<sizeof($title); $i++) {
            // inserisce i txt nel file zip
            $v_list = $filezip->add("./temp/".$_SESSION['nickname']."/".$title[$i].".txt", PCLZIP_OPT_REMOVE_ALL_PATH);
            if ($v_list == 0) { 
                die("Error : ".$filezip->errorInfo(true)); 
            } 
    }
    
    for($i=0; $i<sizeof($title); $i++) {
        unlink("./temp/".$_SESSION['nickname']."/".$title[$i].".txt");
    }
    
    header("Content-type: application/zip"); 
    header("Content-Disposition: attachment; filename=$zipstring"); 
    header("Content-Description: Backup"); 
    header("Content-Length: ".filesize($zipstring)); 
    readfile($zipstring);     
    unlink($zipstring);
    rmdir("./temp/".$_SESSION['nickname']);
    exit;
    

    无论如何,当我尝试使用此库时,我有两个问题:

    1-当我需要创建一个zip时,我使用创建一个名为/temp/username的文件夹。然后,我做拉链。在Firefox上,当我在客户端发送文件时,它在zip文件名的开头添加了语法_temp_username_file name.zip。为什么会这样?

    2-我下载压缩文件,打开它,然后将txt文件打开到这个文件中。当我关闭它时,winrar问我是否要插入新的“数据”,但我不添加任何数据。我只是开闭着。为什么?

    我知道,这是个奇怪的问题,但也许有人也有同样的问题!干杯

    1 回复  |  直到 14 年前
        1
  •  1
  •   mario    14 年前
    1. 输出文件名 _temp_username_filename.zip 来自你的使用 header("Content-Disposition: attachment; filename=$zipstring"); . 你试图嵌入斜线 / 字符,这是火狐不允许的。它转动任何 / 进入之内 _ . 解决方案:如果不喜欢该文件名,请更改 $zipstring 在发送邮件头之前发送到其他邮件。

    2. 这是Winrar特有的行为,与生成的zip文件无关。解决方案:不要使用winrar。

    推荐文章