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['size'] < 1000000 && $fileinfo['size'] > 0){ move_uploaded_file($fileinfo['tmp_name'],$fileinfo['name']); echo '上传成功'; }else{ echo '文件太大或未知'; } } ?> </body> </html>
php, $_FILES detailed explanation, $_FILES php $_FILES Detailed explanation $_FILES