<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>roo.boo</title>
</head>
<body>
<form action="sow.php" method="post" enctype="multipart/form-data">
<label for="file">文件名: </label>
<input type="file" name="file" id="file">
<input type="submit" name="sub">
</form>
<?php
if (isset($_FILES['file'])) {
//允许上传图片的后缀名;
$allowedExt = array("gif","jpeg","png","jpg");
$temp = explode(".", $_FILES['file']['name']);
$exten = end($temp);//获取图片后缀;
if(($_FILES['file']['type'] == "image/jpg")
||($_FILES['file']['type'] == "image/jpeg")
||($_FILES['file']['type'] == "image/pjpeg")
||($_FILES['file']['type'] == "image/png")
||($_FILES['file']['type'] == "image/x-png")
||($_FILES['file']['type'] == "image/gif")
&&($_FILES['file']['size']<204800)
&&in_array($exten, $allowedExt)
){
if($_FILES['file']['error']>0){
echo "文件上传失原因".$_FILES['file']['error']."<br>";
}else {
echo "文件的名字是:".$_FILES['file']['name']."<br>";
echo "文件的大小是:".($_FILES['file']['size']/1024)."kb<br>";
echo "文件的储存位置是:".$_FILES['file']['tmp_name']."<br>";
echo "文件的类型是:".$_FILES['file']['type']."<br>";
if(file_exists("D:/www/www/study/".$_FILES['file']['name'])){
echo "文件已经存在"."D:/www/www/study/".$_FILES['file']['name'];
}else{
move_uploaded_file($_FILES['file']['tmp_name'],"D:www/www/study/".$_FILES['file']['name'] );
echo "文件已经存储在位置"."D:/www/www/study".$_FILES['file']['name'];
}
}
}else {
echo "非法文件格式";
}
}
?>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>roo.boo</title>
</head>
<body>
<form action="sow.php" method="post" enctype="multipart/form-data">
<label for="file">文件名: </label>
<input type="file" name="file" id="file">
<input type="submit" name="sub">
</form>
<?php
if (isset($_FILES['file'])) {
//允许上传图片的后缀名;
$allowedExt = array("gif","jpeg","png","jpg");
$temp = explode(".", $_FILES['file']['name']);
$exten = end($temp);//获取图片后缀;
if(($_FILES['file']['type'] == "image/jpg")
||($_FILES['file']['type'] == "image/jpeg")
||($_FILES['file']['type'] == "image/pjpeg")
||($_FILES['file']['type'] == "image/png")
||($_FILES['file']['type'] == "image/x-png")
||($_FILES['file']['type'] == "image/gif")
&&($_FILES['file']['size']<204800)
&&in_array($exten, $allowedExt)
){
if($_FILES['file']['error']>0){
echo "文件上传失原因".$_FILES['file']['error']."<br>";
}else {
echo "文件的名字是:".$_FILES['file']['name']."<br>";
echo "文件的大小是:".($_FILES['file']['size']/1024)."kb<br>";
echo "文件的储存位置是:".$_FILES['file']['tmp_name']."<br>";
echo "文件的类型是:".$_FILES['file']['type']."<br>";
if(file_exists("D:/www/www/study/".$_FILES['file']['name'])){
echo "文件已经存在"."D:/www/www/study/".$_FILES['file']['name'];
}else{
move_uploaded_file($_FILES['file']['tmp_name'],"D:www/www/study/".$_FILES['file']['name'] );
echo "文件已经存储在位置"."D:/www/www/study".$_FILES['file']['name'];
}
}
}else {
echo "非法文件格式";
}
}
?>
</body>
</html>