<?php $path = './tupian/'; $limit = 300000; $filename = $_FILES['tupian']['name']; $size = $_FILES['tupian']['size']; if ($size > $limit) exit('<script type="text/javascript">alert("文件太大!");history.back();</script>'); $typelimit = array('jpeg','jpg','gif','bmp','gif'); function type($filename) //获取文件后缀名函数 { return substr(strrchr($filename, '.'), 1); } $type = type($filename); if(!in_array($type, $typelimit)) { echo '<script type="text/javascript">alert("文件类型不正确!!");history.back();</script>'; exit; } $time = time(); $newname = $time.".".$type; $lj = $path.$newname; while (file_exists($lj)) { $time = time()+1; $newname = $time.".".$type; $lj = $path.$newname; } move_uploaded_file($_FILES['tupian']['tmp_name'],$lj); echo "上传成功"; ?>
最新评论: