<?php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>限制图片格式</title>
</head>
<body>
<label>请选择要上传的图片(图片格式为“.jpg”)</label>
<form method="post" action="index.php" enctype="multipart/form-data">
<input type="hidden" name="actionl" value="upload" />
<input type="file"name="u_file"/>
<input type="submit" value="上传"/>
</form>
<?php
if($_POST['actionl'] == "upload"){
$file_path = "./uploads\\";
$picture_name=$FILES['u_file']['name'];
$picture_name=strstr($picture_name , ".");
if($picture_name!= ".jpg"){
echo"<script>alert('上传图片格式不正确,请重新上传');window.location.href='index.php';</script>;
}else if($FILES['u_file']['tmp_name]){
move_uploaded_file($_FILES['u_file]['tmp_name],$file_path.$_FILES['u_file]['name];
echo"图片上传成功!";
}
else
echo"上传图片失败";
}
?>
</body>
</html>