网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

php数据压缩 php 解压缩

php curl采集,服务器gzip压缩返回数据怎么办

只需要设置一下CURLOPT_ENCODING属性即可,如下:

创新互联公司成立于2013年,我们提供高端成都网站建设网站制作网站设计、网站定制、全网整合营销推广小程序制作、微信公众号开发、营销推广服务,提供专业营销思路、内容策划、视觉设计、程序开发来完成项目落地,为假山制作企业提供源源不断的流量和订单咨询。

curl_setopt($ch, CURLOPT_ENCODING, "gzip"); //指定gzip压缩

更多PHP cURL内容请搜索我的博客《PHP cURL实现模拟登录与采集使用方法详解教程》

php导出excel表、压缩成文件下载到本地如何实现?

你好!你所提出的三个问题.我没怎麼看懂.如果以第二个为主.我倒可以说说我的看法.

一.如何把数据赋到excel中?

答:sorry.没怎麼明白.见谅.

二.导出为excel表?

答:有两种方法实现.1.phpexcel.(稍显复杂)

2.简单的(我讲这个.简单^_^)直接上代码.自己改一下名字

和字段名.就成.

?php

error_reporting(0);

//屏蔽警告和NOTICE等所有提示.包括error

Header(

"Content-type:

application/octet-stream

");

Header(

"Accept-Ranges:

bytes

");

Header(

"Content-type:application/vnd.ms-excel;charset=Big5");

//此处写编码,如,UTF-8....

Header(

"Content-Disposition:attachment;filename=abnormal_Report.xls

");

//自己写文件名

*.xls

require

"conn_mysql.php";

//连接mysql

$sql

=

"select

*

from

`netart`.`abnormal_records`

order

by

record_abtime

desc";

$result

=

mysql_query($sql,$conn);

echo

"table

width='100%'

border='1'

";

echo"tr";

echo

"td

style='color:red'

font

size=4

ID

/font/td";

echo

"td

style='color:red'

font

size=4异常时间

/font/td";

echo

"td

style='color:red'

font

size=4异常地点

/font/td";

echo

"td

style='color:red'

font

size=4详细内容

/font/td";

echo

"td

style='color:red'

font

size=4提交人

/font/td";

echo

"td

style='color:red'

font

size=4提交时间

/font

/td";

echo

"/tr";

while

($rs=mysql_fetch_array($result)){

echo

"tr";

echo

"td

width='30'

{$rs['record_id']}/td";

//用width

控制表格的宽度.自己改变.

echo

"td

width='150'

{$rs['record_abtime']}/td";

echo

"td

width='80'

{$rs['record_abplace']}/td";

echo

"td

width='700'

{$rs['record_content']}

/td";

echo

"td

width='60'

{$rs['record_username']}

/td";

echo

"td

width='120'

{$rs['record_uptime']}

/td";

echo

"/tr";

}

echo

"/tbale";

?

//以上代码.自己去改一下名字.和字段名就可以运行了.

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

下面的代码针对MSSQL:(基本跟

Mysql一样啦.只是改用了ODBC)

?php

error_reporting(0);

Header(

"Content-type:

application/octet-stream");

Header(

"Accept-Ranges:

bytes

");

Header(

"Content-type:application/vnd.ms-excel;charset=Big5");

Header(

"Content-Disposition:attachment;filename=Syslog_view.xls

");

require

"conn_mssql.php";

session_start();

$flag1=@$_SESSION['flag_1'];

$flag2=@$_SESSION['flag_2'];

$flag3=@$_SESSION['flag_3'];

$content=@$_SESSION['content'];

$ip=@$_SESSION['ip'];

$content_2=@$_SESSION['content_2'];

$ip_2=@$_SESSION['ip_2'];

$time=@$_SESSION['time'];

if($flag1==1)

{

$sql_s="select

SysLog.DateTime,SysLog.IP,SysLog.Message

from

NetPerfMon.dbo.SysLog

where

IP='$ip'

and

convert(varchar(10),DateTime,120)='$time'

order

by

DateTime

desc";}

if($flag2==2)

{

$sql_s="select

SysLog.DateTime,SysLog.IP,SysLog.Message

from

NetPerfMon.dbo.SysLog

where

IP='$ip'

and

convert(varchar(10),DateTime,120)='$time'

order

by

DateTime

desc";}

if($flag3==3)

{$sql_s="select

SysLog.DateTime,SysLog.IP,SysLog.Message

from

NetPerfMon.dbo.SysLog

where

IP='$ip'

and

Message

like

'%$content%'

and

convert(varchar(10),DateTime,120)='$time'

order

by

DateTime

desc";}

$res=odbc_do($link,$sql_s);

echo

"table

width='100%'

border='1'";

echo"tr";

echo

"td

style='color:red'

font

size=4

DateTime

/font/td";

echo

"td

style='color:red'

font

size=4

Switch

IP

/font/td";

echo

"td

style='color:red'

font

size=4

Content/font/td";

echo

"/tr";

while

($rs=odbc_fetch_array($res))

{

echo

"tr";

echo

"td

width='130'

{$rs['DateTime']}/td";

echo

"td

width='110'

{$rs['IP']}/td";

echo

"td

width='800'

{$rs['Message']}/td";

echo

"/tr";

}

echo

"/tbale";

session_stop();

?

三.压缩成文件下载到本地?

答:此处也没怎麼明白.因为,你做个按钮/链接至上面的代码.不就可以保存成excel到本地了..还要做什麼压缩呢.

综:回答完毕.希望能帮到你.

PHP网页上打包文件生成压缩文件zip,并弹出下载

既然你只是想学习如何打包.

那我重点就回答你这一块,正好我刚刚用到;

$filename = "./" . date ( 'YmdH' ) . ".zip"; // 最终生成的文件名(含路径)

// 生成文件

$zip = new ZipArchive (); // 使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释

if ($zip-open ( $filename, ZIPARCHIVE::CREATE ) !== TRUE) {

exit ( '无法打开文件,或者文件创建失败' );

}

//$fileNameArr 就是一个存储文件路径的数组 比如 array('/a/1.jpg,/a/2.jpg....');

foreach ( $fileNameArr as $val ) {

$zip-addFile ( $val, basename ( $val ) ); // 第二个参数是放在压缩包中的文件名称,如果文件可能会有重复,就需要注意一下

}

$zip-close (); // 关闭

//下面是输出下载;

header ( "Cache-Control: max-age=0" );

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 );//输出文件;

thinkphp怎么将文件夹压缩成zip

import('ORG.Util.FileToZip');

// 打包下载

$handler = opendir($cur_file); //$cur_file 文件所在目录

$download_file = array();

$i = 0;

while( ($filename = readdir($handler)) !== false ) {

if($filename != '.' $filename != '..') {

$download_file[$i++] = $filename;

}

}

closedir($handler);

$scandir=new traverseDir($cur_file,$save_path); //$save_path zip包文件目录

$scandir-tozip($download_file);

PHP gzip 压缩后和 java deflate 数据不一致的问题?

gzinflate 是解压 gzdeflate 数据的啊,现在是想压缩后和 java deflate 压缩的数据一致。又看了下资料,java Deflater(int level,boolean nowrap) 压缩,如果参数 'nowrap' 为 true,则不使用 ZLIB 头和校验和字段,默认好像是 false。而采用 PHP gzencode ($data , -1, FORCE_DEFLATE ) 进行压缩,只是带了zlib headers 信息,没有带 crc32 checksum,可能问题就在这儿,但是还不知道怎么解决,还请好心的版主给点建议!


网页标题:php数据压缩 php 解压缩
标题URL:http://bjjierui.cn/article/dososip.html

其他资讯