Home >Backend Development >PHP Tutorial >Pear: HTTP_Upload Introduction_PHP Tutorial
Pear's HTTP_Upload class library provides an encapsulated html form file upload handler, using Pear's error system. Features PLAIN TEXT
Can handle the upload of multiple files at one time
Easy to check the upload status of files and limit unexpected file uploads
Multi-lingual error message (not in Chinese yet, but can be expanded)
Example of single file upload
index.htm
CODE:
files.php
PLAIN TEXT
PHP:
requireHTTP/Upload.php;
$upload=newHTTP_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());
}
}
?>
Example of multiple file upload
PLAIN TEXT
CODE:
Copyright statement: You can reprint at will. When reprinting, please be sure to indicate the original source and author information of the article and this statement in the form of a hyperlink
Author: volcano Published on August 30, 2006 at 9:58 am
Copyright information: You can reprint at will. When reprinting, please be sure to indicate the original source and author information of the article and this statement in the form of a hyperlink
Permanent link - http://www.ooso.net/index.php/archives/240