<!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>
<?php
$image = $_FILES['mypicture'];
$imageName = $image['name'];
$tmp_name = $image['tmp_name'];
$error = $image['error'];
$dirName = $_POST['dirName'];
print_r($image);
if(is_uploaded_file($tmp_name))
{
if(is_dir($dirName))
{
chdir($dirName);
$path = $dirName.'/'.$imageName;
move_uploaded_file($tmp_name,$path);
echo "<img src='".$path."'>";
}
else
{
mkdir($dirName,0777);
chdir($dirName);
$path = $dirName.'/'.$imageName;
move_uploaded_file($tmp_name,$path);
echo "<img src='".$path."'>";
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="mypicture" accept="image/gif , image/jpeg , image/jpg , image/png" />
上传到文件夹名称:
<input type="text" name="dirName" />
<input type="submit" name="bnt" value="上传" />
</form>
</body>
</html>