File upload for beginners in PHP
Through PHP, files can be uploaded to the server
We will demonstrate it through code
文件上传
As shown in the above code, the form is submitted to file.php. The file.php code is as follows
* 1:超过了文件大小,在php.ini文件中设置
* 2:超过了文件的大小MAX_FILE_SIZE选项指定的值
* 3:文件只有部分被上传
* 4:没有文件被上传
* 5:上传文件大小为0 */ $error=$upfile["error"];//上传后系统返回的值 echo "================
"; echo "上传文件名称是:".$name."
"; echo "上传文件类型是:".$type."
"; echo "上传文件大小是:".$size."
"; echo "上传后系统返回的值是:".$error."
"; echo "上传文件的临时存放路径是:".$tmp_name."
"; echo "开始移动上传文件
"; //把上传的临时文件移动到up目录下面 //move_uploaded_file($tmp_name,'up/'.$name); $destination="up/".$name; echo "================
"; echo "上传信息:
"; if($error==0){ echo "文件上传成功啦!"; //echo " alt=\"图片预览:\r文件名:".$destination."\r上传时间:\">"; }elseif ($error==1){ echo "超过了文件大小,在php.ini文件中设置"; }elseif ($error==2){ echo "超过了文件的大小MAX_FILE_SIZE选项指定的值"; }elseif ($error==3){ echo "文件只有部分被上传"; }elseif ($error==4){ echo "没有文件被上传"; }else{ echo "上传文件大小为0"; } }else{ echo "请上传jpg,gif,png等格式的图片!"; } } ?>
Note: For the above two pieces of code, please create two files yourself, copy the code into it, and put it on the local server for debugging
When we select a picture, it will Output the information, such as path, suffix, etc.