move_uploaded_file():
此函数仅用于通过 HTTP POST 上传的文件。
如果目标文件已经存在,将会被覆盖。
$code = $_FILES['userfile']['error'];
if( $code > 0) { //判断文件是否成功上传到服务器,0表示上传成功
echo 'Error: '.$code;
switch ( $code ) {
case UPLOAD_ERR_OK:
//0:没有错误,上传成功的文件。
$response = 'There is no error, the file uploaded with success.';
break;
case UPLOAD_ERR_INI_SIZE:
//1:上传文件在php.ini中超过upload_max_filesize指令
$response = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
break;
case UPLOAD_ERR_FORM_SIZE:
//2:上传的文件超过了在HTML表单中指定的max_file_size指令。
$response = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
break;
case UPLOAD_ERR_PARTIAL:
//3:上传的文件只是部分上传。
$response = 'The uploaded file was only partially uploaded.';
break;
case UPLOAD_ERR_NO_FILE:
//4:没有上传文件。
$response = 'No file was uploaded.';
break;
case UPLOAD_ERR_NO_TMP_DIR:
//6:缺少一个临时文件夹中。在PHP 4.3.10和PHP 5.0.3中引入。
$response = 'Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.';
break;
case UPLOAD_ERR_CANT_WRITE:
//7:未能将文件写入磁盘。
$response = 'Failed to write file to disk. Introduced in PHP 5.1.0.';
break;
case UPLOAD_ERR_EXTENSION:
//8:PHP扩展停止了文件上传。PHP没有提供一种方法来确定是哪个扩展导致了文件上载停止
$response = 'A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop;';
break;
default:
//未知的错误
$response = 'Unknown error';
break;
}
echo $response;
exit; //如果$_FILES['userfile']['error']大于0都是有错误,输出错误信息并退出程序
}else{
echo "success".$code;
$file = $_FILES['userfile'];
var_dump($file);
die;
}