php $_FILES detailed explanation $_FILES

巴扎黑
Release: 2016-11-23 11:18:00
Original
9238 people have browsed it

php $_FILES Detailed explanation of $_FILES
Variables submitted to the script via HTTP POST file upload. Similar to the old $HTTP_POST_FILES array (still valid, but deprecated). See POST method upload for details.

$_FILES array content is as follows:

$_FILES['userfile']['name']

The original name of the client machine file.

$_FILES['userfile']['type']
The MIME type of the file, which requires the browser to provide support for this information, such as "image/gif".

$_FILES['userfile']['size']
The size of the uploaded file, in bytes.

$_FILES['userfile']['tmp_name']
The temporary file name stored on the server after the file is uploaded.

$_FILES['userfile']['error']
Error code related to the file upload. ['error'] was added in PHP 4.2.0.
Note: Before PHP 4.1.0, the name of this array was $HTTP_POST_FILES, which is not an automatic global variable like $_FILES. PHP 3 does not support the $HTTP_POST_FILES array.
move_uploaded_file -- Move the uploaded file to a new location
Description
bool move_uploaded_file (string filename, string destination)


This function checks and ensures that the file specified by filename is a legal uploaded file (i.e. uploaded via PHP's HTTP POST uploaded by the mechanism). If the file is legal, it is moved to the file specified by destination.

If filename is not a legal uploaded file, no operation will occur and move_uploaded_file() will return FALSE.

If filename is a valid uploaded file but cannot be moved for some reason, no action will occur and move_uploaded_file() will return FALSE. A warning is also issued.

This kind of check is particularly important, if the uploaded file may cause its content to be displayed to the user or other users of this system


PHP single file upload

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>单文件上传</title>
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
--> 
</style></head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form">
<input name="up_file" type="file" />
<input type="submit" name="submit" value="上传" />
</form>
<?php
if(!empty($_FILES[up_file][name])){
$fileinfo = $_FILES[up_file];
if($fileinfo[&#39;size&#39;] < 1000000 && $fileinfo[&#39;size&#39;] > 0){
   move_uploaded_file($fileinfo[&#39;tmp_name&#39;],$fileinfo[&#39;name&#39;]);
   echo &#39;上传成功&#39;;
}else{
   echo &#39;文件太大或未知&#39;;
}
}
?>
</body>
</html>
Copy after login

php, $_FILES detailed explanation, $_FILES php $_FILES Detailed explanation $_FILES

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template