$sort=12;
$f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");//设置可上传的文件类型
$file_size_max=200*1024*1024;//限制单个文件上传最大容量
$overwrite = 0;//是否允许覆盖相同文件,1:允许,0:不允许
$f_input="files";//设置上传域名称
foreach($_files[$f_input]["error"] as $key => $error){
$up_error="no";
if ($error == upload_err_ok){
$f_name=$_files[$f_input]['name'][$key];//获取上传源文件名
$uploadfile=$uploaddir.strtolower(basename($f_name));
$tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
$tmp_type=strtolower($tmp_type);
if(!stristr($f_type,$tmp_type)){
echo "<script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>";
$up_error="yes";
}
if ($_files[$f_input]['size'][$key]>$file_size_max) {
echo "<script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_files[$f_input]
['size'][$key]/1024)."kb,大于规定的".($file_size_max/1024)."kb,上传失败!')</script>";
$up_error="yes";
}
if (file_exists($uploadfile)&&!$overwrite){
echo "<script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>";
$up_error="yes";
}
$string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
$rand .= substr($string,mt_rand(0,strlen($string)-1),1);
$t=date("ymdhis").substr($gettime[0],2,6).$rand;
$attdir="./file/";
if(!is_dir($attdir))
{ mkdir($attdir);}
$uploadfile=$attdir.$t.".".$tmp_type;
if(($up_error!="yes") and (move_uploaded_file($_files[$f_input]['tmp_name']
[$key], $uploadfile))){
$_msg=$_msg.$f_name.'上传成功 ';
}
else{
$_msg=$_msg.$f_name.'上传失败 ';
}
}
}
echo "<script>window.parent.finish('".$_msg."');</script>";
?>
第二款文件上传代码
<?php
$destination_path = '../../upfile/jianjulogo/';//getcwd().directory_separator;
$result = 0;
$target_path = $destination_path . basename( $_files['myfile']['name']);
if(@move_uploaded_file($_files['myfile']['tmp_name'], $target_path)) {
$result = 1;
}
echo $target_path;
sleep(1);
?>
<script language="网页特效" type="text/javascript">window.top.window.stopupload(<?php echo $result; ?>,'<?=$target_path?>');</script>