上传图片功能:
获取当前文件夹位置,上传到当前文件夹下
为了上传后文件名重复导致覆盖,上传后更改名字为:当前时间+原文件名
只允许gif、jpeg、bmg、jpg格式的文件上传
<form name="frm1" enctype="multipart/form-data" action="" method="post"> <input name="filename" type="file" style="border:solid 1px #6ac1e2; width: 200px; border-radius: 5px"/> <input name="submit" type="submit" value="提交" style="background-color: #e28c8e;border-radius: 5px; font-size: 14px;"/> </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("image/gif","image/jpeg","image/bmg","image/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.‘"/>‘; } } ?>
时间: 2024-10-25 12:48:15