上传图片功能:
获取当前文件夹位置,上传到当前文件夹下
为了上传后文件名重复导致覆盖,上传后更改名字为:当前时间+原文件名
只允许gif、jpeg、bmg、jpg格式的文件上传
<form name="frm1" enctype="multipart/form-data" action="" method="post">
<input name="filename" type="file" />
<input name="submit" type="submit" value="提交" />
</form>
<?php
if(isset($_POST['submit'])) {
$dir = dirname(__FILE__);
$dir = str_replace("//", "/", $dir) . "/";
date_default_timezone_set("PRC");
$date = date( "YmdHis");
$filename = $date.$_FILES['filename']['name'];
$uploadfile = $dir . $filename;
$tp = array("p_w_picpath/gif","p_w_picpath/jpeg","p_w_picpath/bmg","p_w_picpath/jpg");
if(!in_array($_FILES["filename"]["type"],$tp)) {
echo '<script>alert("允许上传的图片格式:jpg/jpeg/gif/bmp")</script>';
}else{
$r_sc = move_uploaded_file($_FILES['filename']["tmp_name"],$uploadfile);
echo '<img src="'.$filename.'"/>';
}
}
?>