zoukankan      html  css  js  c++  java
  • php保存远程文件到本地的方法

    用到了ob_start();
    <?php header("Content-type:text/html charset=utf-8"); if(!empty($_POST['post'])){ $url=$_POST['url']; $fileName=$_POST['fileName']; $fileName=grabImage($url,$fileName); echo "<img src="$fileName" width='300px' height='300px'/>"; } function grabImage($url,$fileName){ if($url=="") return false; $p=strrpos($url,"."); $exp=substr($url,$p+1); if($fileName=="") $fileName=mt_rand(100000,999999).".".$ext; if($exp=="gif" || $exp=="jepg" || $exp=="png" || $exp=="jpg"){ ob_start(); readfile($url); $content=ob_get_contents(); ob_end_clean(); $f=fopen($fileName,"w"); fwrite($f,$content); fclose($f); }else{ return false; } return $fileName; } ?> <form action="" method="post"> 图片地址:<input type="text" name="url" /><br/> 保存地址:<input type="text" name="fileName"/><br/> <input type="submit" name="post" value="下载"/> </form>
  • 相关阅读:
    SQL优化
    Mybatis
    Spring MVC(总结二)
    ES多机集群配置
    ES索引,分片,一致性
    ElasticSearch关于索引库的命令操作
    试题01(一)
    Linux安装配置elastic search
    Windows安装配置elastic search
    SpringBoot(二)
  • 原文地址:https://www.cnblogs.com/xiaoyueer/p/3388740.html
Copyright © 2011-2022 走看看