资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php压缩数据后下载,下载文件变成php怎么解决

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

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

十载的诸城网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。网络营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整诸城建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联建站从事“诸城网站设计”,“诸城网站推广”以来,每个客户项目都认真落实执行。

一.如何把数据赋到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 如何把文件夹及文件夹下面的所有文件打包成压缩包,在页面上用户点击下载按钮即可下载到本地?

一般不会下载的时候重新打包,因为php打包是一个非常消耗资源的过程。

使用php zip 打包,然后记录包的路径,下载的时候直接下载该路径文件即可。

php导出excel表后,打包成压缩包,然后下载到本地如何实现?

用PHPExcel,PHPExcel是相当强大的 MS Office Excel 文档生成类库。

你上它的官/网把程序包下/载下来,里面有 PHPExcel 的程序、还有30个实例程序和三个文档。

看一下其中的开发文档你就会用了。

读取(这段在开发文档里有的,在13页):

require_once '../Classes/PHPExcel/IOFactory.php';

$objReader = PHPExcel_IOFactory::createReader('Excel2007');

$objReader-setReadDataOnly(true);

$objPHPExcel = $objReader-load("test.xlsx");

$objWorksheet = $objPHPExcel-getActiveSheet();

echo 'table' . "\n";

foreach ($objWorksheet-getRowIterator() as $row) {

echo 'tr' . "\n";

$cellIterator = $row-getCellIterator();

$cellIterator-setIterateOnlyExistingCells(false);

foreach ($cellIterator as $cell) {

echo 'td' . $cell-getValue() . '/td' . "\n";

}

echo '/tr' . "\n";

}

echo '/table' . "\n";

?

php如何实现两个文件先压缩成一个压缩包然后下载

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


当前文章:php压缩数据后下载,下载文件变成php怎么解决
新闻来源:http://cdkjz.cn/article/dsgsshp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220