Pear::HTTP_Upload简介
Pear的HTTP_Upload类库提供了一个封装好的html表单文件上传处理程序,使用Pear的error系统。
特点
能一次处理多个文件的上传
容易校验文件的上传状态,限制不期望的文件上传
多语种的报错提示信息(还没有中文,不过可以扩展)
单个文件上传的例子
index.htm
PLAIN TEXT
CODE:
<form action="./files.php" enctype="multipart/form-data">
File 1: <input type="file" name="userfile"><br>
<input type="submit" name="submit" value="Upload!">
</form>
files.php
PLAIN TEXT
PHP:
<?php
require 'HTTP/Upload.php';
$upload = new HTTP_Upload('es');
// Language for error messages
$file = $upload->getFiles('userfile');
// return a file object or error
if (PEAR::isError($file)) {
die ($file->getMessage());
}
// Check if the file is a valid upload
if ($file->isValid()) { // this method will return the name of the file [...]