<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>File Upload</title>
</head>
<body>
<form enctype="multipart/form-data" action="test.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
Send this File:<input name="userfile" type="file"/>
<input type="submit" value="Send File" />
</form>
</body>
</html>
$_FILE['userfile']['name'] : 客户端机器文件的原名称
$_FILE['userfile']['type'] : 文件的MIME类型
$_FILE['userfile']['size'] : 已上传的文件大小
$_FILE['userfile']['tmpname'] : 文件被上传后在
服务器存储的临时文件名
$_FILE['userfile']['error'] : 和该文件上传的错误代码
<?php
//接收并处理上传数据
function processFile($files, $type) {
$uploadName = null;
foreach ($files as $name => $value) {
$originalName = $value['name'];
$arr = explode(".", $originalName);
$postfix = $arr[count($arr) - 1];
$tmpPath = $value['tmp_name'];
$tmpType = $value['type'];
$tmpSize = $value['size'];
}
$newname = EhlStaticFunction::generateRandomStr(40).".".$postfix;
switch ($type) {
case 1 :
// 处理声音文件
$destination = VIDEOUPLOADDIR.$newname;
break;
case 2 :
// 处理图像文件
$destination = IMAGEUPLOADDIR.$newname;
break;
}
move_uploaded_file($tmpPath, $destination);
}