天涯海角路
<html><head>
<meta http-equiv="Content-Type" content="text/html; " />
<title>PHP使用is_uploaded_file()函数和move_uploaded_file()函数将上传文件移动到指定目录示例-www.baike369.com</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
选择文件:<input type="file" name="upfile" />
<input type="submit" name="sub" value="上传" />
</form>
<?php
if(isset($_POST['sub'])){ // isset()函数判断提交按钮值是否存在
if(!is_dir("images")){ // is_dir()函数判断指定的文件夹是否存在
mkdir("images"); // mkdir()函数创建文件夹
}
$file=$_FILES['upfile']; // 获取上传文件
if(is_uploaded_file($file['tmp_name'])){ // 判断上传是不是通过HTTP POST上传的
$str=stristr($file['name'],'.'); // stristr()函数获取上传文件的后缀
// strtotime()函数定义一个Unix时间戳
$path="images/".strtotime("now").$str; // 定义上传文件的存储位置
if(move_uploaded_file($file['tmp_name'],$path)){ // 执行文件上传操作
echo "上传成功,文件名称为:".strtotime("now").$str;
}
}
}
?>
</body>
</html>
页:
[1]