level 2
狂是一种孤傲
楼主
1.uploadhtml
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>图片上传客户端文件</title>
<style type="text/css">
body {
font-family: "微软雅黑";
font-size: 14px;
margin: 0px;
}
</style>
<script>
function check()
{
if(document.getElementById("txtFile").value == "")
{
alert("请选择一个文件!");
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data" onSubmit="return check()">
<input type="file" id="txtFile" name="txtFile"><input type="submit" value="上传">
</form>
</body>
</html>
2.uploadphp
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>图片上传服务端文件</title>
</head>
<body>
<pre>
<?php
$oldName = $_FILES["txtFile"]["name"];
$fileType = $_FILES["txtFile"]["type"];
$tmpPath = $_FILES["txtFile"]["tmp_name"];
$errorCount = $_FILES["txtFile"]["error"];
$fileSize = $_FILES["txtFile"]["size"];
$extName = strtolower(substr($oldName,strrpos($oldName,".")));
if($errorCount > 0)
{
echo "<script>
alert('请选择一个文件以上传');
history.go(-1);
</script>";
}
else if(substr_count(".jpg\.jpeg\.gif\.png\.bmp",$extName) == 0 )
{
echo "<script>
alert('请上传后缀为JPG|JPEG|GIF|PNG|BMP的图片文件');
history.go(-1);
</script>";
}
else if($fileSize > 2 * 1024 * 1024)
{
echo "<script>
alert('请上传大小在2M以内的图片文件');
history.go(-1);
</script>";
}
else
{
$newPath = "uploads/".date("Ymd")."/";
if(!is_dir("uploads/"))
{
mkdir("uploads/");
}
else
{
if(!is_dir($newPath))
{
mkdir($newPath);
}
}
$newName = date("YmdHis").substr(microtime(),2,6).$extName;
$newPath = $newPath.$newName;
//echo $newPath;
move_uploaded_file($tmpPath,$newPath);
echo "<script>
alert('上传成功');
history.go(-1);
</script>";
}
?>
</pre>
</body>
</html>
2021年06月17日 06点06分
1
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>图片上传客户端文件</title>
<style type="text/css">
body {
font-family: "微软雅黑";
font-size: 14px;
margin: 0px;
}
</style>
<script>
function check()
{
if(document.getElementById("txtFile").value == "")
{
alert("请选择一个文件!");
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data" onSubmit="return check()">
<input type="file" id="txtFile" name="txtFile"><input type="submit" value="上传">
</form>
</body>
</html>
2.uploadphp
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>图片上传服务端文件</title>
</head>
<body>
<pre>
<?php
$oldName = $_FILES["txtFile"]["name"];
$fileType = $_FILES["txtFile"]["type"];
$tmpPath = $_FILES["txtFile"]["tmp_name"];
$errorCount = $_FILES["txtFile"]["error"];
$fileSize = $_FILES["txtFile"]["size"];
$extName = strtolower(substr($oldName,strrpos($oldName,".")));
if($errorCount > 0)
{
echo "<script>
alert('请选择一个文件以上传');
history.go(-1);
</script>";
}
else if(substr_count(".jpg\.jpeg\.gif\.png\.bmp",$extName) == 0 )
{
echo "<script>
alert('请上传后缀为JPG|JPEG|GIF|PNG|BMP的图片文件');
history.go(-1);
</script>";
}
else if($fileSize > 2 * 1024 * 1024)
{
echo "<script>
alert('请上传大小在2M以内的图片文件');
history.go(-1);
</script>";
}
else
{
$newPath = "uploads/".date("Ymd")."/";
if(!is_dir("uploads/"))
{
mkdir("uploads/");
}
else
{
if(!is_dir($newPath))
{
mkdir($newPath);
}
}
$newName = date("YmdHis").substr(microtime(),2,6).$extName;
$newPath = $newPath.$newName;
//echo $newPath;
move_uploaded_file($tmpPath,$newPath);
echo "<script>
alert('上传成功');
history.go(-1);
</script>";
}
?>
</pre>
</body>
</html>