PHPExcel 在linux下输出excel
http://blog.c3crm.com/node/820
起初用1.7.6的不行,windows正常,linux无法输出excel..
只好按照上文换用1.7.2…ok了
Warning: require_once() [function.require-once]: URL using bad/illegal format or missing URL in /var/www/Classes/PHPExcel.php on line 50
经过google搜索,有的同学通过升级到PHP5.3.1版本解决,但易客CRM用的PHP5.2.x,不能通过此方法解决,皇天不负有心人,终于找到了解决方法,原来只需注释掉一行代码即可。
解决方法:
把 PHPExcel.php 文件里面的 require_once ‘PHPExcel/Shared/ZipStreamWrapper.php’; 这行代码注释掉即可,估计和zip相关的程序有关。
在此感谢Google和PHPChina。
PS:易客CRM中有关Excel的处理将全部转向PHPExcel库。
看了看PHPExcel 1.7.6的install.txt…原来是要输出Excel2007格式的xsx,要有php_zip的支持.
要有php_zip模块….
http://blog.csdn.net/binger819623/article/details/6228968
http://yang2001.blog.51cto.com/25307/212322
http://hi.baidu.com/ubuntu2me/blog/item/c41a0211920464f0c3ce79d1.html
wget http://pecl.php.net/get/zip-1.8.10.tgz //貌似已经出新版本了zip1.10.2.tgz
tar zxvf zip-1.8.3.tgz
cd 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文件名不能更改)
make
make install
//此时会在zip/modules/下生成一个zip.so文件,将它拷贝到make之后给的一个路径下,如有同名的,覆盖之。
2、生成的模块路径:
/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/zip.so (对应的extensions路径)
3、修改php.ini
extension_dir = “./”修改为extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/”
增加extension=zip.so
4、重启apache
apache2/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);