<html>
<head>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
</head>
<body>
<img src="" id="img" onclick="file.click()" alt="选择上传图片" style="width:380px;height:200px;line-height:200px;margin-bottom:10px;">
<form action="index.php" id="logo" enctype="multipart/form-data" method="post">
<input type="file" name="file" style="display:none" id="file" onchange="logo.submit()" />
</form>
</body>
</html>
<?php
if(empty($_POST))
{
if (($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")|| ($_FILES["file"]["type"] == "image/pjpeg"))
{
if($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
if (file_exists("uploads/" . date('Ymd',time()).$_FILES["file"]["name"]))
{
echo " 图片已经存在!!! ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/" . date('Ymd',time()).$_FILES["file"]["name"]);
$name = "uploads/" . date('Ymd',time()).$_FILES["file"]["name"];
echo "<script>$('#img').attr('src','".$name."');</script>";
}
}
}
else
{
echo "上传失败!!!";
}
}
?>