Pear:http_upload Introduction

Source: Internet
Author: User
Tags file upload getmessage html form pear

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.