- 论坛徽章:
- 0
|
- <form enctype="multipart/form-data" action="__URL__" method="POST">
- <!-- MAX_FILE_SIZE must precede the file input field -->
- <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
- <!-- Name of input element determines name in $_FILES array -->
- Send this file: <input name="userfile" type="file" />
- <input type="submit" value="Send File" />
- </form>
复制代码
$_FILES['userfile']['name']
客户端机器文件的原名称。
$_FILES['userfile']['type']
文件的 MIME 类型,如果浏览器提供此信息的话。一个例子是“image/gif”。不过此 MIME 类型在 PHP 端并不检查,因此不要想当然认为有这个值。
$_FILES['userfile']['size']
已上传文件的大小,单位为字节。
$_FILES['userfile']['tmp_name']
文件被上传后在服务端储存的临时文件名。
$_FILES['userfile']['error']
和该文件上传相关的错误代码
- $uploaddir = '/var/www/uploads/';
- $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
- echo '<pre>';
- if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
- echo "File is valid, and was successfully uploaded. ";
- } else {
- echo "Possible file upload attack! ";
- }
复制代码 |
|