文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Pear::HTTP_Upload简介

Pear::HTTP_Upload简介

时间:2008-05-17  来源:剑心通明


Pear的HTTP_Upload类库提供了一个封装好的html表单文件上传处理程序,使用
Pear
的error系统。
特点

  • 能一次处理多个文件的上传
  • 容易校验文件的上传状态,限制不期望的文件上传
  • 多语种的报错提示信息(还没有中文,不过可以扩展)

单个文件上传的例子
index.htm
PLAIN TEXT
CODE:
"./files.php" enctype="multipart/form-data">
File 1: "file" name="userfile">
"submit" name="submit" value="Upload!">

files.php
PLAIN TEXT
[url=javascript:;]PHP[/url]
:
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());
    }
}
?>
多文件上传的例子
PLAIN TEXT
CODE:
"files.php" enctype="multipart/form-data">
Image 1: "file" name="userfile[]">
Image 2: "file" name="userfile[]">
Image 3: "file" name="userfile[]">
"submit" name="sub" value="Upload!">
PLAIN TEXT
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
版权声明:可以任意
[url=javascript:;]转载[/url]
,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明
作者:
volcano
发表于8月 30, 2006 at 9:58 am
版权信息
: 可以任意转载, 转载时请务必以超链接形式标明文章
原始出处

作者信息
及此声明
永久链接 - http://www.ooso.net/index.php/archives/240



相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载