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

    function get_url_image($url)
    {
    $ext = explode('.', $url);
    $ext = strtolower(end($ext));
    if($ext != "gif" && $ext != "jpg" && $ext != "png" && $ext != "bmp" && $ext != "jpeg")
    {
    return $url;
    }

    $name = date('Ymd');
    for ($i = 0; $i < 6; $i++)
    {
    $name .= chr(mt_rand(97, 122));
    }
    $name .= '.' . $ext;
    $target = ROOT_PATH . DATA_DIR . '/afficheimg/' . $name;

    $tmp_file = DATA_DIR . '/afficheimg/' . $name;
    $filename = ROOT_PATH . $tmp_file;

    $img = file_get_contents($url);

    $fp = @fopen($filename, "a");
    fwrite($fp, $img);
    fclose($fp);

    return $tmp_file;
    }
    ————————————————
    // 主图上传
    if ($_FILES['topic_img']['name'] && $_FILES['topic_img']['size'] > 0)
    {
    /* 检查文件合法性 */
    if(!get_file_suffix($_FILES['topic_img']['name'], $allow_suffix))
    {
    sys_msg($_LANG['invalid_type']);
    }

    /* 处理 */
    $name = date('Ymd');
    for ($i = 0; $i < 6; $i++)
    {
    $name .= chr(mt_rand(97, 122));
    }
    $name .= '.' . end(explode('.', $_FILES['topic_img']['name']));
    $target = ROOT_PATH . DATA_DIR . '/afficheimg/' . $name;

    if (move_upload_file($_FILES['topic_img']['tmp_name'], $target))
    {
    $topic_img = DATA_DIR . '/afficheimg/' . $name;
    }
    }
    else if (!empty($_REQUEST['url']))
    {
    /* 来自互联网图片 不可以是服务器地址 */
    if(strstr($_REQUEST['url'], 'http') && !strstr($_REQUEST['url'], $_SERVER['SERVER_NAME']))
    {
    /* 取互联网图片至本地 */
    $topic_img = get_url_image($_REQUEST['url']);
    }
    else{
    sys_msg($_LANG['web_url_no']);
    }
    }
  • 相关阅读:
    Mac上的抓包工具Charles[转载]
    js 实现自动调出键盘
    Mac下git安装(使用Xcode)
    weinre远程调试
    Css Sprite Demo
    sublime 常用快捷键
    css 盒子模型 以及 box-sizing属性
    jquery中bind,live,delegate,on的区别
    模拟实现库函数的atoi、atof和itoa
    常见排序算法
  • 原文地址:https://www.cnblogs.com/csjoz/p/7244117.html
Copyright © 2011-2022 走看看