<span>php
</span><span>
</span><span>
$sTemp
</span> = <span>
strrchr
</span>(<span>
$filename
</span>,
"."
<span>);
</span><span>
return
</span><span>
substr
</span>(<span>
$sTemp
</span>, 1<span>);
}
</span><span>
function
</span> fileext2(<span>
$filename
</span><span>){
</span><span>
$sTemp
</span> = <span>
explode
</span>(
"."
, <span>
$filename
</span><span>);
</span><span>
return
</span><span>
$sTemp
</span>[<span>
count
</span>(<span>
$sTemp
</span>)-1<span>];
}
</span><span>
</span><span>
$captchaSource
</span> =
"0123456789abcdefghijklmnopqrstuvwxyz这是一个随机打印输出字符串的例子"
<span>;
</span><span>
$captchaResult
</span> =
"2015"
; <span>
</span><span>
$n
</span> = <span>rand</span>(0, 35); <span>#</span><span>
strlen
(
$captchaSource
));</span><span>
if
</span>(<span>
$n
</span> >= 36<span>){
</span><span>
$n
</span> = 36 + <span>
ceil
</span>((<span>
$n
</span>-36)/3) * 3<span>;
</span><span>
$captchaResult
</span> .= <span>
substr
</span>(<span>
$captchaSource
</span>, <span>
$n
</span>, 3<span>);
}</span><span>
else
</span><span>{
</span><span>
$captchaResult
</span> .= <span>
substr
</span>(<span>
$captchaSource
</span>, <span>
$n
</span>, 1<span>);
}
}
</span><span>
return
</span><span>
$captchaResult
</span><span>;
}
</span><span>
$type
</span> = <span>
array
</span>(
"jpg"
,
"gif"
,
"bmp"
,
"jpeg"
,
"png"
<span>);
</span><span>
</span><span>
$uploadfilename
</span> = random(8<span>);
</span><span>
if
</span>(<span>in_array</span>(<span>
$fileext
</span>, <span>
$type
</span><span>)){
</span><span>
$filename
</span> = <span>
explode
</span>(
"."
, <span>
$_FILES
</span>[
'file'
][
'name'
<span>]);
</span><span>
if
</span>(<span>
is_uploaded_file
</span>(<span>
$_FILES
</span>[
'file'
][
'tmp_name'
<span>])){
</span><span>
</span><span>
if
</span>(<span>
$flag
</span><span>){
</span><span>
echo
</span>
"上传成功!"
<span>;
}</span><span>
else
</span><span>{
</span><span>
echo
</span>
"Error."
<span>;
}
</span><span>
echo
</span>
"<a>Back</a>"
<span>;
}
}
</span>?>
<meta http-equiv=
"content-type"
c charset=
"utf-8"
>
<title>Upload Image</title>