Heim >Backend-Entwicklung >PHP-Tutorial >如何实现图片下载
有这样一个地址 打开这个地址是图片 http://qr.topscan.com/api.php?text=x
想实现这样的一个功能
1.html
点击下载图片
1.php
$filename= http://qr.topscan.com/api.php?text=x
header('Content-type: image/jpeg');
header("Content-Disposition: attachment; filename='$filename'");
这样没办法下载图片,请教一下大家应该怎么写
即使能下载,下载的图片也是不显示的
<?php$file = 'test.zip';$filename = '中文.zip';if(file_exists($file)){ $user_agent = $_SERVER['Http_User_agent']; $encode_filename = rawurlencode($filename); if(preg_match("/MSIE/", $user_agent)){ header('content-disposition:attachment; filename="'.$encode_filename.'"'); }else if(preg_match("/Firefox/", $user_agent)){ header("content-disposition:attachment; filename*=\"utf8''".$filename.'"'); }else{ header('content-disposition:attachment; filename="'.$filename.'"'); } readfile($file);}?>
<?php$file = 'test.zip';$filename = '中文.zip';if(file_exists($file)){ $user_agent = $_SERVER['Http_User_agent']; $encode_filename = rawurlencode($filename); if(preg_match("/MSIE/", $user_agent)){ header('content-disposition:attachment; filename="'.$encode_filename.'"'); }else if(preg_match("/Firefox/", $user_agent)){ header("content-disposition:attachment; filename*=\"utf8''".$filename.'"'); }else{ header('content-disposition:attachment; filename="'.$filename.'"'); } readfile($file);}?>
<?php$filename= 'http://qr.topscan.com/api.php?text=x'; if(file_exists($filename)){ $user_agent = $_SERVER['Http_User_agent']; $encode_filename = rawurlencode($filename); if(preg_match("/MSIE/", $user_agent)){ header('content-disposition:attachment; filename="'.$encode_filename.'"'); }else if(preg_match("/Firefox/", $user_agent)){ header("content-disposition:attachment; filename*=\"utf8''".$filename.'"'); }else{ header('content-disposition:attachment; filename="'.$filename.'"'); } echo 333; readfile($filename);}// header('Content-type: image/jpeg'); //header("Content-Disposition: attachment; filename='$filename'"); ?>
不明白你们在干什么?
点击下载图片
如果是为了显示图片,则 1.php 为
echo file_get_contents('http://qr.topscan.com/api.php?text=x');
$s = file_get_contents('http://qr.topscan.com/api.php?text=x');Header("Content-type: application/force-download");Header("Accept-Ranges:bytes");Header("Accept-Length:" . strlen($s));Header("Content-Disposition: attachment; filename=x.png");echo $s;
不明白你们在干什么?
点击下载图片
如果是为了显示图片,则 1.php 为
echo file_get_contents('http://qr.topscan.com/api.php?text=x');
$s = file_get_contents('http://qr.topscan.com/api.php?text=x');Header("Content-type: application/force-download");Header("Accept-Ranges:bytes");Header("Accept-Length:" . strlen($s));Header("Content-Disposition: attachment; filename=x.png");echo $s;
commit 是提交事务
开启事务
若干条 SQL 指令
如果任意一条失败 rollback
commit
commit 是提交事务
开启事务
若干条 SQL 指令
如果任意一条失败 rollback
commit