调用
<iframe frameborder=”0″ width=”390″ height=”22″ scrolling=”No” src=”up.php”></iframe>
以下是程序的代码
//up.php
<style type=”text/css”>
<!–
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
body,td,th {
font-size: 16px;
color: #FF0000;
}
a:link {
color: #CC0000;
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
–>
</style>
<?php if ($_GET[‘act’]==””){?>
<form enctype=”multipart/form-data” action=up.php?act=save method=post>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”2000000″>
<input type=file name=upfile size=20>
<input type=submit value=’上传文件’>
</form>
<?php }?>
<?php if ($_GET[‘act’]==”save”){
function getname($exname){
$dir = “../tmp/”;
$i=1;
if(!is_dir($dir)){
mkdir($dir,0777);
}
while(true){
if(!is_file($dir.$i.”.”.$exname)){
$name=$i.”.”.$exname;
break;
}
$i++;
}
return $dir.$name;
}
$exname=strtolower(substr($_FILES[‘upfile’][‘name’],(strrpos($_FILES[‘upfile’][‘name’],’.’)+1)));
$uploadfile = getname($exname);
if (move_uploaded_file($_FILES[‘upfile’][‘tmp_name’], $uploadfile)) {
echo “<h3><font color=#ff0000>文件上传成功<a href=up.php>重新上传</a>!</font></h3>”;
echo “<script language=”javascript”>parent.form1.photo.value='”.$uploadfile.”‘</script>”;
echo “<script language=”javascript”>parent.form1.picnews.checked=’checked'</script>”;
} else {
echo “<h3><font color=#ff0000>文件上传失败!<a href=up.php>重新上传</a></font></h3>”;
}
}?>