字体:  

求一个好用的PHP单文件上传类

chxugao 发表于: 2008-7-31 16:53 来源: PHPChina 开源社区门户

求一个好用的PHP单文件上传类
请高手们分享一下!!
谢谢!

[ 本帖最后由 chxugao 于 2008-7-31 16:56 编辑 ]

最新回复

hedgelog at 2008-7-31 16:56:35
没有类只函数
chxugao at 2008-7-31 17:00:33
也行啊..发个来研究研究
chxugao at 2008-7-31 17:02:31
在线等待着
kuhanzhu at 2008-7-31 17:30:12
看手册自己写一个呗。
chxugao at 2008-7-31 17:35:47
能力有限...请多谅解
yagas at 2008-7-31 17:40:01
不知道这个行不行?
http://iebphp.uu1001.com/read.php?tid=5
sara at 2008-7-31 17:48:08
其他程序中抓一个?
chxugao at 2008-7-31 17:58:15
这个好像不太好用吧
欧阳 at 2008-8-01 08:58:44
pear  upload
gug365 at 2008-8-03 23:36:01
我的博客有的,文件上传类
guofang at 2008-8-04 11:01:52
naodai at 2008-8-04 13:39:56
先自己写个嘛,
多写几个就好了,
yong4614926 at 2008-10-30 09:45:17
upload.php
<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
}
?>