1、$_ FILES [] ['name ']: Uploaded file name
2、$_ FILES [] ['type ']: uploaded file type
3、$_ FILES [] ['size ']: size of the file, in bytes
4、$_ FILES [] ['tmp_name ']: temporary file during file upload
5、$_ FILES [] ['error ']: error code (values are 0, 1, 2, 3, 4, 6, 7) 0 means correct
Html file code:
<form method="post" action="info.php" enctype="multipart/form-data"> <input type="file" name="f"> <input type="submit" name="button" value="提交"> </form>
PHP file code (info. php):
<?php if(!empty($_POST)){ if($_FILES['f']['error']==0){ // 文件上传 move_uploaded_file保存上传的文件,并重命名防止文件名冲突 $path='./'.substr($_FILES['f']['name'],0,strpos($_FILES['f']['name'],'.')).uniqid('').strrchr($_FILES['f']['name'],'.'); move_uploaded_file($_FILES['f']['tmp_name'],$path); }else{ echo '上传有误'; echo '错误码:'.$_FILES['f']['error']; } } ?>