文件上传类
2024-05-04 22:04:33
供稿:网友
使用示例:
upload.php
<?php
include_once "upload.class.php";
if ($Submit != '')
{
$fileArr['file'] = $file;
$fileArr['name'] = $file_name;
$fileArr['size'] = $file_size;
$fileArr['type'] = $file_type;
/** 所允许上传的文件类型 */
$filetypes = array('gif','jpg','jpge','png');
/** 文件上传目录 */
$savepath = "/usr/htdocs/upload/";
/** 没有最大限制 0 无限制*/
$maxsize = 0;
/** 覆盖 0 不允许 1 允许 */
$overwrite = 0;
$upload = new upload($fileArr, $file_name, $savepath, $filetypes, $overwrite, $maxsize);
if (!$upload->run())
{
echo "上传失败".$upload->errmsg();
}
}
?>
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" enctype="multipart/form-data" method="post" action="">
<input type="file" name="file">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
上传类
upload.class.php
<?php
//
// +----------------------------------------------------------------------+
// | 文件上传
|// | 本代码仅供学习讨论之用,允许随意修改
|// | Author: whxbb(whxbb@21cn.com)
|// +----------------------------------------------------------------------+
//
// $Id: upload.class.php,v 1.0 2001/10/14 14:06:57 whxbb Exp $
//
$UPLOAD_CLASS_ERROR = array( 1 => '不允许上传该格式文件',
2 => '目录不可写',