上传图片

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="ap.php" method="post" enctype="multipart/form-data">

<input type="file" name="shang">
<input type="submit" name="but" value="上传文件">

</form>
</body>
</html>

<?php
header("Content-Type: text/html; charset=utf-8");
$sc=$_FILES["shang"]["name"];
$scc=$_FILES["shang"]["tmp_name"];
$a=explode(".", $sc);
$b=array_pop($a);
$sccs=time().mt_rand();
$name=$sccs.".".$b;
$path='uploads/'.$name;
if ($_FILES["shang"]["error"]==0) {
if (move_uploaded_file($scc, $path)) {
echo "成功";
}
else{
echo "错误2";
}
}
else{
echo "错误";
}

posted @ 2017-12-25 11:13  彬斌宾  阅读(63)  评论(0)    收藏  举报