您的位置:PHPChina 开源社区门户 >> 论坛 >> PHP基础编程(问答求助) >> 查看帖子
字体: 小 中 大
chxugao 发表于: 2008-7-31 16:53 来源: PHPChina 开源社区门户
最新回复
http://iebphp.uu1001.com/read.php?tid=5
http://home.phpchina.com/space.p ... o=blog&id=36041
多写几个就好了,
<html>
<head>
<title>上传文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="style.css">
<script language=JavaScript>
function mysubmit(theform)
{
if(theform.file.value=="")
{
alert("请点击浏览按钮,选择您要上传的文件!")
theform.file.focus;
return (false);
}
if (theform.file.size >100000)
{
alert("图片大小超过了限制!");
theform.file.value="";
theform.file.focus();
return (false);
}
}
return (true);
}
</script>
</head>
<body bgcolor="F2F2F2" leftmargin="0" topmargin="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<form method="post" action="upload_sr.php" enctype="multipart/form-data" name="loadimage" onSubmit="return mysubmit(this)">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="10485760" />
<td><input name="file" type="file" class="input" size="20">
<input type="submit" name="submit" value="上传" class="bottom"> <font color="red" style="font-size:12px">提示:</font>上传前最好对文件进行压缩处理!
</td>
</form>
</tr>
</table>
</body>
</html>
upload_sr.php
<?
$dir=$_FILES['file']['tmp_name'];
$num=rand(100000,999999);
$pix=substr($_FILES['file']['name'],(strlen($_FILES['file']['name'])-4),4);
$dest="pic/".date("Ymdhis").$num.$pix;
copy($dir,$dest);
if($_FILES['file']['size']>0){
?>
<html>
<head>
<title>上传成功</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language=JavaScript>
function image_success()
{
alert("文件上传成功!");
parent.form1.turl.value="<?php echo $dest;?>";
window.location="upload.php";
}
</script>
</head>
<body bgcolor="#F2F2F2" leftmargin="0" topmargin="0" onLoad="image_success()">
</body>
</html>
<?php }else{?>
<html>
<head>
<title>类型不匹配</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language=JavaScript>
function error_type()
{
alert("上传失败,请重新上传!");
window.location="upload.php";
}
</script>
</head>
<body bgcolor="#F2F2F2" leftmargin="0" topmargin="0" onLoad="error_type()">
</body>
</html>
<?php
}
?>