在php中单击从新窗口下载图像
我想从浏览器的新窗口下载图像。意思是当我点击图像时,它应该出现在新窗口中,并且有一个按钮可以下载它 到目前为止,我能够下载它在一次点击,而不是在新窗口中打开意味着当我点击图像浏览器弹出窗口生成打开或保存图像。但我想先在新窗口中打开图像,然后按下下载按钮 这是我正在使用的代码在php中单击从新窗口下载图像,php,javascript,image,browser,download,Php,Javascript,Image,Browser,Download,我想从浏览器的新窗口下载图像。意思是当我点击图像时,它应该出现在新窗口中,并且有一个按钮可以下载它 到目前为止,我能够下载它在一次点击,而不是在新窗口中打开意味着当我点击图像浏览器弹出窗口生成打开或保存图像。但我想先在新窗口中打开图像,然后按下下载按钮 这是我正在使用的代码 <?php if(isset($_GET['file'])){ //Please give the Path like this $file = $_GET['file']; if (file
<?php
if(isset($_GET['file'])){
//Please give the Path like this
$file = $_GET['file'];
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
}
?>
添加两个$\u GET
变量,一个用于检查是否指定了文件
,另一个用于下载
。对于文件,只需使用内容类型:image/jpeg
放置图像即可。然后,放置一个下载按钮,然后再次单击,传递一个$\u GET['download']
,这将允许用户使用与所发布的相同的代码进行下载。@DreamEater您能给我代码吗。