php创建目录及上传文件代码!
header("Content-type: text/html; charset=utf-8");
//上传文件代码
if($_FILES["file"]["error"] > 0)
{
echo "错误:" . $_FILES["file"]["error"];
}
else
{
echo "文件名:" . $_FILES["file"]["name"] . "<br />";
echo "类型:" . $_FILES["file"]["type"] . "<br />";
echo "大小:" . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "存储位置:" . $_FILES["file"]["tmp_name"] . "<br /><br />";
//判断目录aaa是否存在,否则创建目录
if(!is_dir("aaa/"))
{
mkdir("aaa/", "0777");
echo "创建目录成功!";
}
if(file_exists("update/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " 已存在!";
}
else
{
$file_name = md5(date("YmdGis")) . $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"], "update/" . $file_name);
echo "文件成功存储到:" . "update/" . $file_name;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="update_file.php" method="post" enctype="multipart/form-data">
文件名:
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="提交" />
</form>
</body>
</html>