Pear's Http_upload class library provides an encapsulated HTML form file upload handler that uses Pear's error system.
Characteristics
Ability to process multiple file uploads at a time
Easy to check file upload status, limit not expected file upload
Multi-lingual error message (no Chinese yet, but can be extended)
Example of a single file upload
index.htm
PLAIN TEXT
CODE:
<form action="./files.php"enctype="multipart/form-data">
File1: <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=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());
}
}
?>
Examples of multiple file uploads
PLAIN TEXT
CODE:
<form action="files.php"enctype="multipart/form-data">
Image1: <input type="file"name="userfile[]">
<br>Image2: <input type="file"name="userfile[]">
<br>Image3: <input type="file"name="userfile[]">
<br><input type="submit"name="sub"value="Upload!"></form>
PLAIN TEXT
PHP:
<?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 NOTICE: You can reprint, reprint, please be sure to hyperlink form to indicate the original source of the article and author information and this statement
Author: Volcano published in August, 2006 at 9:58 am
Copyright information: You can reprint, reprint, please be sure to hyperlink form to indicate the original source of the article and author information and this statement