zoukankan      html  css  js  c++  java
  • php图片下载

    直接用url会在浏览器中打开图片,

    想直接弹出保存框,可以用下面方法

    下面的$dir指的是图片在服务器的绝对地址

    function iDownload(){
    
            $name=$_GET['name']; //获取图片地址$file = fopen($dir,"r"); // 打开文件   
            $dir='/www/image/';$ext=strrchr($name,"."); 
            
            if($ext!=".gif" && $ext!=".jpg" && $ext!=".png") 
                return false; 
    
            $file_path=$dir.$name;
            $size=filesize($file_path);
            $file = fopen($file_path,"r") or die("file is not exist");; // 打开文件  
            
            Header("Content-type: application/octet-stream"); 
            Header("Accept-Ranges: bytes"); 
            Header("Accept-Length: ".$size); 
            Header("Content-Disposition: attachment; filename=" . $name); 
            echo fread($file,$size); 
            fclose($file); 
            exit; 
        }
  • 相关阅读:
    Extension Methods(扩展方法)
    linux面试题
    渗透测试 day4
    渗透测试 day3
    渗透测试 day2
    渗透测试 day1
    9.3 网络安全介绍
    9.2 Iptables
    8.30 进程管理
    8.29 linux的网络
  • 原文地址:https://www.cnblogs.com/baby123/p/5554522.html
Copyright © 2011-2022 走看看