<form enctype="multipart/form-data" action="upload.php" method="post"> <label for="file">请选择上传的文件</label> <input type="file" name="file" /> <br /> <input type="submit" name="submit" value="确定" /> </form>
<?php//文件存储路径$file_path="upload/";//664权限为文件属主和属组用户可读和写,其他只读。if(is_dir($file_path)!=TRUE) mkdir($file_path,0664) ;//定义允许上传的文件扩展名$ext_arr = array("gif", "jpg", "jpeg", "png", "bmp");if (empty($_FILES) === false) { //判断检查 if($photo_up_size > 2097155){ exit("sorry,您上传的照片不能超过2M"); } if($_FILES["file"]["error"] > 0){ exit("文件上传发生错误:".$_FILES["file"]["error"]); } //获得文件扩展名 $temp_arr = explode(".", $_FILES["file"]["name"]); $file_ext = array_pop($temp_arr); $file_ext = trim($file_ext); $file_ext = strtolower($file_ext); //检查扩展名 if (in_array($file_ext, $ext_arr) === false) { exit("上传文件扩展名是不允许"); } //以时间戳重命名文件 $new_name = time().".".$file_ext; //将文件移动到存储目录下 move_uploaded_file($_FILES["file"]["tmp_name"],"$file_path" . $new_name); //向数据表写入文件存储信息 // 向数据表插入上传保存的信息 。。。。。// echo "文件上传成功!"; exit;} else { echo "文件上传失败!";}?>
原生php upload
最新推荐文章于 2021-03-09 22:23:47 发布