随机用户名 头像 php,PHP随机图片/头像

专为给喜欢逛论坛的你设计...<?php

$path = "./img/". preg_replace('/[^a-zA-Z0-9]/i','',$_GET['id'] );

if (is_dir($path)){

$url = $path  ;

}

else {

$url =  "./img/nobird";

}

$files = array();

if(false !== ($handle = @opendir($url)))

{

while($file = readdir($handle))

{

if(($file !== ".")&&($file !== ".."))

{

if((substr($file,-3) == "gif") || (substr($file,-3) == "jpg") || (substr($file,-3) == "png"))

$files[count($files)] = $file;

}

}

closedir($handle);

$random = rand(0,(count($files)-1)); //设定随机数的范围;

//根据文件类型,设置输出的文件类型;

if(substr($files[$random],-3) == "gif")

header("Content-type:image/gif");

elseif(substr($files[$random],-3) == "jpg")

header("Content-type:image/jpeg");

elseif(substr($files[$random],-3) == "png")

header("Content-type:image/png");

readfile("$url/$files[$random]"); //读文件,显示图片;

}else

{

$im = imagecreatetruecolor(500, 100);

$bgc = imagecolorallocate($im, 255, 255, 255);

$tc = imagecolorallocate($im, 0, 0, 0);

imagefilledrectangle($im, 0, 0, 500, 100, $bgc);

imagettftext($im,15,0,5,20,$tc,$font,iconv("gb2312","UTF-8","图片载入出错,请向我报告!"));

imagettftext($im,15,0,6,36,$tc,$font,iconv("gb2312","UTF-8",$imgname));

}

?>

和网上流传甚多的版本比较起来,这个支持id,也就是说,一个文件,可以为多个账户服务(我就是一篇凑数的文章,你特么来咬我呀).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值