当前位置:首页 - PHP编程技巧 - 正文
Pear::HTTP_Upload简介
发布时间: 2008-4-16 10:43 作者: volcano 信息来源: ooso.net
Pear的HTTP_Upload类库提供了一个封装好的html表单文件上传处理程序,使用Pear的error系统。
特点
- 能一次处理多个文件的上传
- 容易校验文件的上传状态,限制不期望的文件上传
- 多语种的报错提示信息(还没有中文,不过可以扩展)
单个文件上传的例子
index.htm
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
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 you moved,
-
// useful for example to save the name in a database
-
$file_name = $file->moveTo('./uploads_dir/');
-
if (PEAR::isError($file_name)) {
-
die ($file_name->getMessage());
-
}
-
}
-
?>
多文件上传的例子
CODE:
-
<form action="files.php" enctype="multipart/form-data">
-
Image 1: <input type="file" name="userfile[]">
-
<br>Image 2: <input type="file" name="userfile[]">
-
<br>Image 3: <input type="file" name="userfile[]">
-
<br><input type="submit" name="sub" value="Upload!"></form>
PHP:
-
<?php
-
$files = $upload->getFiles(); // returns an array of file objects or error
-
foreach ($files as $file) {
-
if ($file->isValid()) {
-
...
-
}
-
}?>
下载
http://pear.php.net/package/HTTP_Upload
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明
作者: volcano 发表于8月 30, 2006 at 9:58 am
版权信息: 可以任意转载, 转载时请务必以超链接形式标明文章原始出处和作者信息及此声明
永久链接 - http://www.ooso.net/index.php/archives/240
查看评论>> 发表评论
最热评论
- · 连载(六) Java桥 (5日)
- · Google Trends:哪种程序语言最受关注 (30日)
- · 连载(五) Session Clustering (15日)
- · 连载(四)Web服务器集群管理 (11日)
- · 连载(三) PHP监控系统 (31日)
- · 连载(二) 性能优化 (21日)
相关文章
- · 北京培训中心PCTI-17期周末班开始招生啦!! (29日)
- · 北京金秋9月实战精英班热招! (29日)
- · 北京LAMP八期“免费”就业直通车-权威认证+项目实训+保障就业! (29日)
- · 使用存储过程的5个好处 (27日)
- · 修改MySQL 5.0的默认100连接数 (27日)
- · MySQL5.0的my.cnf配置说明 (27日)





