php如何下载动态图片保存到本地?

php如何下载动态图片保存到本地?,第1张

php 远程下载文件

function httpcopy($url, $file="", $timeout=60) {

$file = empty($file) ? pathinfo($url,PATHINFO_BASENAME) : $file

$dir = pathinfo($file,PATHINFO_DIRNAME)

!is_dir($dir) &&@mkdir($dir,0755,true)

$url = str_replace(" ","%20",$url)

if(function_exists('curl_init')) {

$ch = curl_init()

curl_setopt($ch, CURLOPT_URL, $url)

curl_setopt($ch, CURLOPT_TIMEOUT, $timeout)

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE)

$temp = curl_exec($ch)

if(@file_put_contents($file, $temp) &&!curl_error($ch)) {

return $file

} else {

return false

}

} else {

$opts = array(

"http"=>array(

"method"=>"GET",

"header"=>"",

"timeout"=>$timeout)

)

$context = stream_context_create($opts)

if(@copy($url, $file, $context)) {

//$http_response_header

return $file

} else {

return false

}

}

}

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

一.如何把数据赋到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-excelcharset=Big5")

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

Header(

"Content-Disposition:attachmentfilename=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-excelcharset=Big5")

Header(

"Content-Disposition:attachmentfilename=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到本地了..还要做什麼压缩呢.

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12027508.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存