zoukankan      html  css  js  c++  java
  • 抓取远程图片到本地,你会用什么函数?

    <?php

    function getImg($url, $fileName=''){
    if($url=='') die('地址参数错误');
    if($fileName == ''){
    $ext_name = strrchr($url, '.');
    $allow_ext = ['.gif', '.jpg', '.gif', '.jpeg'];
    if(!in_array($ext_name, $allow_ext)) die('文件格式不对');
    $new_file_name = time().$ext_name;
    }
    ob_start(); //打开缓存
    readfile($url);//读入一个文件并写入到输出缓冲。
    $img_file = ob_get_contents(); //获取缓存保存到变量
    ob_end_clean();//关闭并清除缓存
    $local = fopen($new_file_name, 'ab');
    fwrite($local, $img_file);
    fclose($local);
    return $fileName;
    }

    echo getImg("http://www.mysqltutorial.org/wp-content/uploads/2008/05/mysqltutorial.gif");

    /* 还有其他函数,比如:

    file_get_contents();

    file_put_contents();

    */

  • 相关阅读:
    Java Class的field如果以小写t开头
    ACM集训日志——day1——15.7.8
    分金币 Uva 11300
    RMQ小结
    Poj 水题
    Codeforces Round #278 (Div. 2)
    poj 3685
    poj 3579
    vConsole
    js更换自定义鼠标指针图片
  • 原文地址:https://www.cnblogs.com/zhang19950924/p/12665179.html
Copyright © 2011-2022 走看看