Home >Backend Development >PHP Tutorial >Pear: HTTP_Upload Introduction_PHP Tutorial

Pear: HTTP_Upload Introduction_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:36:48784browse

Pear's HTTP_Upload class library provides an encapsulated html form file upload handler, using Pear's error system.

Features
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

PLAIN TEXT
CODE:


File1:



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:


Image1:

Image2:

Image3:


PLAIN TEXT
PHP :
$files=$upload->getFiles();// returns an array of file objects or error
foreach($filesas$file){
if($ file->isValid()){
 … 
 }
}?>
Download
http://pear.php.net/package/HTTP_Upload

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486637.htmlTechArticlePear's HTTP_Upload class library provides an encapsulated html form file upload handler, using Pear's error system. Features: Can handle the upload of multiple files at one time. Easy to verify the upload of files...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn