这个是我写的 一个,其中有些是已经定义好的变量
$date = date('Ymd');
$attach_dir= date('Ymd').'_'."attach";//非图片上传路径
$r = count($_FILES['attach']['name']);
$attach_nu=$r-2;
for($i=1; $i <= $attach_nu; $i++ )
{
$dir= ATTACH_URL.$date."/";
$dir_R= ATTACH_URL.$attach_dir."/";
$IMG_SIZE="4169764";
$extname=strtolower(substr($_FILES['attach']['name'][$i],(strrpos($_FILES['attach']['name'][$i],'.')+1)));
if($_FILES['attach']['size'][$i] < $IMG_SIZE )
{
$filename= $date."_".$_FILES['attach']['name'][$i];
$md = date('Ymd').'_'.md5(microtime());
$FILE= $_FILES['attach']['name'][$i];
$uploadfile = $dir.$md.".".$extname;
$uploadfile_R = $dir_R.$filename;
$img_url=attach_url.$date."/".$md.".".$extname; //图片路径
$attach_url=attach_url.$attach_dir."/".$filename;//非图片路径
if("jpg" == $extname || "gif" == $extname || "png" == $extname
)
{
if ( !is_dir($dir))
{mkdir ($dir);}
if(move_uploaded_file($_FILES['attach']['tmp_name'][$i],$uploadfile))
{
$localattach='/\[localimg=(\d{1,3}),(\d{1,3})\]'.$localid[$i].'\[\/localimg\]/is';
preg_match($localattach, $text, $matches);
$attachimg= "<img src=".$img_url." width=".$matches[1]." height=".$matches[2]."></img>";
$text = preg_replace($localattach,$attachimg,$text );
}
else{
echo "失败!" ; return false; }
}
else if("rar"==$extname || "zip"==$extname||"torrent"== $extname)
{
if ( !is_dir($dir_R) ){mkdir($dir_R);}
if(move_uploaded_file($_FILES['attach']['tmp_name'][$i],$uploadfile_R))
{
$local_attach='/\[local\]'.$localid[$i].'\[\/local\]/is';
$attach_img= "<a href=".$attach_url.">".$filename."</a>";
$text = preg_replace($local_attach,$attach_img,$text );
echo $local;
}
else{echo "error!";return false;}
}
else{echo "不支持该类型文件上传!"; return false;}
}
else { echo $_FILES['attach']['name'][$i]."这个文件超过论坛要求大小,如有需要请返回操作!"; return false;}
}