Linux平台下PHP zip模块

    技术2022-05-19  20

    Linux平台下PHP安装zip模块 2011-01-29 14:55

    1、依次运行以下命令:wget http://pecl.php.net/get/zip-1.8.10.tgz  //貌似已经出新版本了zip1.10.2.tgztar zxvf zip-1.8.3.tgzcd zip-1.8.3/usr/local/php/bin/phpize   (对应的phpize路径)(安装好的php位置)configure --with-php-config=/usr/local/php/bin/php-config (对应的php-config路径)(php-config文件名不能更改)makemake install//此时会在zip/modules/下生成一个zip.so文件,将它拷贝到make之后给的一个路径下,如有同名的,覆盖之。2、生成的模块路径:/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/zip.so   (对应的extensions路径)3、修改php.iniextension_dir = "./"修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"增加extension=zip.so4、重启apacheapache2/bin/apachectl restart

    ==========================================

    php 利用ZipArchive 实现文件打包

     

    $filename = "./test/test.zip"; //最终生成的 文件名(含路径)   if(!file_exists($filename)){       //重新生成文件       $zip = new ZipArchive();//使用本 类,linux需开启 zlib,windows需取消php_zip.dll前的注释       if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {           exit('无法打开文件,或 者文件创建失败');        }       foreach( $datalist as $val){           $attachfile = $attachmentDir . $val['filepath'];    //获取原始 文件路径           if(file_exists($attachfile)){               $zip->addFile( $attachfile , basename($attachfile));//第二个参 数是放在压缩包中的文件名称,如果文件可能会有重复,就需要注意一下            }        }       $zip->close();//关闭   }   if( !file_exists($filename)){       exit("无法找到文件"); //即使创建,仍有可能失败。。。。   }   header("Cache-Control: public");    header("Content-Description: File Transfer");    header('Content-disposition: attachment; filename='.basename($filename)); //文件名   header("Content-Type: application/zip"); //zip格式的   header("Content-Transfer-Encoding: binary");    //告诉浏览 器,这是二进制文件    header('Content-Length: '. filesize($filename));    //告诉浏览 器,文件大小   @readfile($filename);   

    最新回复(0)