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']);
}
}