一、之前环境已经有了。这里不记录了
二、代码分析
do/swfupfile.php
<?php
require(dirname(__FILE__)."/".'global.php');
if($_POST){
if( !ereg("^[0-9a-z_]+$",$dir) ){
$dir="other";
}
$array[name]=is_array($Filedata)?$_FILES[Filedata][name]:$Filedata_name;
$array[path]=$webdb[updir]."/".$dir;
$array[size]=is_array($Filedata)?$_FILES[Filedata][size]:$Filedata_size;
$array[updateTable]=1;
//统计用户上传的文件占用空间大小
list($lfjid,$lfjuid)=explode("\t",mymd5($_POST[str],'DE'));
$filename=upfile(is_array($Filedata)?$_FILES[Filedata][tmp_name]:$Filedata,$array);
/*
ob_end_clean();
ob_start();
print_r($_POST);
$c=ob_get_contents();ob_end_clean();
write_file('a.txt',$c);
*/
if(!$filename){
echo "";
}else {
$newfile="$dir/$filename";
echo "$newfile|$array[name]|$array[size]";
}
}
?>
上传文件函数:
/**
*上传文件
**/
function upfile($upfile,$array){
global $db,$lfjuid,$pre,$webdb,$groupdb,$lfjdb,$timestamp;
$FY=strtolower(strrchr(basename($upfile),"."));if($FY&&$FY!='.tmp'){die("<SCRIPT>alert('上传文件有误');</SCRIPT>");}
$filename=$array[name];
$path=makepath(ROOT_PATH.$array[path]);
if($path=='false')
{
showerr("不能创建目录$array[path],上传失败",1);
}
elseif(!is_writable($path))
{
showerr("目录不可写".$path,1);
}
$size=abs($array[size]);
$filetype=strtolower(strrchr($filename,"."));
if(!$upfile)
{
showerr("文件不存在,上传失败",1);
}
elseif(!$filetype)
{
showerr("文件不存在,或文件无后缀名,上传失败",1);
}
else
{
if($filetype=='.php'||$filetype=='.asp'||$filetype=='.aspx'||$filetype=='.jsp'||$filetype=='.cgi'){
showerr("系统不允许上传可执行文件,上传失败",1);
}
if( $groupdb[upfileType] && !in_array($filetype,explode(" ",$groupdb[upfileType])) )
{
showerr("你所上传的文件格式为:$filetype,而你所在用户组仅允许上传的文件格式为:$groupdb[upfileType]",1);
}
elseif( !in_array($filetype,explode(" ",$webdb[upfileType])) )
{
showerr("你所上传的文件格式为:$filetype,而系统仅允许上传的文件格式为:$webdb[upfileType]",1);
}
if( $groupdb[upfileMaxSize] && ($groupdb[upfileMaxSize]*1024)<$size )
{
showerr("你所上传的文件大小为:".($size/1024)."K,而你所在用户组仅允许上传的文件大小为:{$groupdb[upfileMaxSize]}K",1);
}
if( !$groupdb[upfileMaxSize] && $webdb[upfileMaxSize] && ($webdb[upfileMaxSize]*1024)<$size )
{
showerr("你所上传的文件大小为:".($size/1024)."K,而系统仅允许上传的文件大小为:{$webdb[upfileMaxSize]}K",1);
}
}
$oldname=preg_replace("/(.*)\.([^.]*)/is","\\1",$filename);
//if(eregi("(.jpg|.png|.gif)$",$filetype)){
// $tempname="{$lfjuid}_".date("YmdHms_",time()).rands(5).$filetype;
//}else{
$tempname="{$lfjuid}_".date("YmdHms_",time()).base64_encode(urlencode($oldname)).$filetype;
//$tempname=str_replace('+','%2B',$tempname);
//}
if(strlen($tempname)>250||strstr($tempname,'+')){
$tempname="{$lfjuid}_".date("YmdHms_",time()).rands(5).$filetype;
}
$newfile="$path/$tempname";
if(@move_uploaded_file($upfile,$newfile))
{
@chmod($newfile, 0777);
$ck=2;
}
if(!$ck)
{
if(@copy($upfile,$newfile))
{
@chmod($newfile, 0777);
$ck=2;
}
}
if($ck)
{
if(($array[size]+$lfjdb[usespace])>($webdb[totalSpace]*1048576+$groupdb[totalspace]*1048576+$lfjdb[totalspace])){
//有的用户组不限制空间大小,$array[updateTable]
if(!$groupdb[AllowUploadMax]){
unlink($newfile);
showerr("你的空间不足,上传失败,你可以联系管理员帮你增大空间!",1);
}
}
$db->query("UPDATE {$pre}memberdata SET usespace=usespace+'$size' WHERE uid='$lfjuid' ");
//对附件做处理,删除冗余的附件.对附件做个记录
$url=str_replace("$webdb[updir]/","",$array[path]);
$db->query("INSERT INTO `{$pre}upfile` ( `uid` , `posttime` , `url` , `filename` , `num`, `if_tmp` ) VALUES ('$lfjuid','$timestamp','$url','tmp-$tempname','1','1')");
setcookie("IF_upfile",$timestamp);
return $tempname;
}
else
{
showerr("请检查空间问题,上传失败",1);
}
}
自己写个html提交表单:
<form name="form1" method="post" action="http://192.168.189.129/qibo/do/swfupload.php" enctype="multipart/form-data">
<input id="postfile" type="file" name="Filedata" style="height:20px; background-color:#EBEBEB; border:1 solid black;" onMouseOver ="this.style.backgroundColor='#F0F0F0'" onMouseOut ="this.style.backgroundColor='#FAFAFA'" onblur="post('')">
<input type="submit" name="Submit" value="上传文件" style="height:20px; background-color:#EBEBEB; border:1 solid black;" onMouseOver ="this.style.backgroundColor='#F0F0F0'" onMouseOut ="this.style.backgroundColor='#FAFAFA'" >
<input type="hidden" name="action" value="uploadfile">
</form>
随便上传一个png文件,
可以无限上传文件。。。。。。
这里可以上传的格式有: