<form enctype="multipart/form-data" name="cpform" method="post">
<input type="hidden" name="do" value="add" />
<br />
<table cellpadding="4" cellspacing="0" border="0" align="center" width="90%">
<tr >
<td>图片文件</td>
<td><input type=file name=imgfile>
</td>
</tr>
</table>
<br />
<table cellpadding="4" cellspacing="0" border="0" align="center" width="90%" class="tborder">
<tr>
<td class="tfoot" colspan="2" align="center"> <input type="submit" class="button" tabindex="1" value=" 确定 " accesskey="s" />
<input type="reset" class="button" tabindex="1" value=" 重置 " accesskey="r" />
</td>
</tr>
</table>
</form>
<?php
if ($_POST['do'] == 'add')
{
$targetFileName = md5(uniqid(microtime(),1));//$token = md5(uniqid(rand()));
//另外一种随机数唯一值算法
if(is_uploaded_file($_FILES["imgfile"]["tmp_name"]))
{
if(move_uploaded_file($_FILES["imgfile"]["tmp_name"],'./img/'."$targetFileName"))
echo '上传图片成功,请';
}
else
{
echo "上传" . $_FILES["imgfile"]["name"] . "失败!!<br>";
}
}
?>