define(PHP_SELF, 'up.php'); #このスクリプト名
define(PHP_SELF2, 'up.htm'); #入り口ファイル名
define(LOGFILE, 'up.log'); #ログファイル名
define(SRC_DIR, 'src/'); #ファイル保存dir
define(PREFIX, 'f'); #ファイル接頭辞
define(MAX_FILE, '2000000'); #ファイル最大bytes
define(MAX_LOG, '30'); #保存件数
while(list($key,$val)=each($_POST)){$_POST[$key]=Escstr($val);}
while(list($key,$val)=each($_GET)){$_GET[$key]=Escstr($val);}
extract($_POST);
$name=$_FILES["up"]["name"];
$mime=Escstr($_FILES['up']['type']);
$up=$_FILES["up"]["tmp_name"];
$allowext = array(asf,avi,bmp,c,exe,gif,htm,jpg,lzh,mid,mov,mp3,mpg,pdf,png,psd,ram,rar,rm,swf,txt,wav,wma,zip);
function regist($com,$up,$name,$mime,$pass){
global $allowext;
$time = time();
$tim = $time.substr(microtime(),2,3);
if($_FILES["up"]["error"]==2){error("でかい。");}
if($name&&$_FILES["up"]["size"]==0){error("でかい、又はあぷできない。");}
if($up&&file_exists($up)&&$size=filesize($up)){
if($size>MAX_FILE){error("でかい。");}
$dest = SRC_DIR.$tim.'.tmp';
move_uploaded_file($up, $dest);
if(!$pass){$pass='dummy';}
$pass = md5($pass);
$youbi = array('日','月','火','水','木','金','土');
$now = date("y/m/d(",$time).(string)$youbi[date("w",$time)].date(")H:i",$time);
$ext = ereg_replace("^.*\\.",".",$name);
$ext = substr(strtolower($ext),0,5);
$flag=FALSE;
foreach($allowext as $value){
if('.'.$value==$ext){$flag=TRUE;}
}
if(!$flag){$ext='.xxx';}
$size=(int)($size/1000);
$fp = fopen(LOGFILE,"r+");
flock($fp,2);
rewind($fp);
$buf=fread($fp,90000);
$line = explode("\n",$buf);
$countline=count($line);
for($i = 0; $i < $countline; $i++){
if($line[$i]){$line[$i].="\n";}
}
if($countline >= MAX_LOG){
for($d=$countline-1;$d>=MAX_LOG-1;$d--){
list($dno,$dname,)=explode("\t",$line[$d]);
if(is_file(SRC_DIR.$dname)){unlink(SRC_DIR.$dname);}
$line[$d]='';
}
}
list($lastno,) = explode("\t", $line[0]);
$no=sprintf("%04d",++$lastno);
$name=PREFIX.$no.$ext;
$newline = "$no\t$name\t$now\t$pass\t$com\t$mime\t$size\t\n";
$newline.= implode('', $line);
ftruncate($fp,0);
set_file_buffer($fp, 0);
rewind($fp);
fputs($fp, $newline);
fclose($fp);
rename($dest,SRC_DIR.$name);
chmod(SRC_DIR.$name,0666);
}
}
function usrdel($no,$pass){
if($pass){
$pass = md5($pass);
$fp = fopen(LOGFILE, "r+");
flock($fp, 2);
rewind($fp);
$buf=fread($fp,90000);
$line = explode("\n",$buf);
$countline=count($line);
for($i = 0; $i < $countline; $i++){
if($line[$i]){$line[$i].="\n";}
list($dno,$dname,,$dpass,)=explode("\t",$line[$i]);
if($dno==$no){
if($dpass==$pass){
if(is_file(SRC_DIR.$dname)){unlink(SRC_DIR.$dname);}
$line[$i]='';
}else{error("パス違う。");}
}
}
$newline= implode('', $line);
ftruncate($fp,0);
set_file_buffer($fp, 0);
rewind($fp);
fputs($fp, $newline);
fclose($fp);
}else{
head($buf);
$buf.='
';
echo $buf;
exit;
}
}
function Escstr($str){
$str = htmlspecialchars($str);
if(get_magic_quotes_gpc()){$str=stripslashes($str);}
return ereg_replace("[\r\n\x09]", "", $str);
}
function head(&$buf){
$buf='
phpテスト中…。
';
}
function updatelog(){
head($buf);
$buf.='
';
$line=file(LOGFILE);
$countline = count($line);
$buf.="ACT | NAME | COMENT | SIZE(KB) | MIME | DATE |
\n";
for($i=0;$i<$countline;$i++){
list($no,$name,$now,,$com,$mime,$size,) = explode("\t", $line[$i]);
$href=SRC_DIR.$name;
$buf.="D | ".
"[$name] | ".
"$com | $size | ".
"$mime | $now |
\n";
}
$buf.='
';
$fp = fopen(PHP_SELF2, "w");
set_file_buffer($fp, 0);
fputs($fp,$buf);
fclose($fp);
}
function error($mes,$dest=''){
if($dest&&is_file($dest)) unlink($dest);
head($dat);
echo $dat."
".
"$mes
リロード".
"