previousCookies (Previous) (Next) Request headersnext

View this page in Last updated: Sun, 28 Jun 2009
English | Brazilian Portuguese | Chinese | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Turkish

File uploads

File uploads – Uploading files via HTTP

How to use file uploads

Upload a PDF document

In this example a file named /home/johndoe/text.pdf is uploaded to the remote machine upload.example.com. Additionally Basic Authentication is used to ensure that John is allowed to upload something.

<?php
require_once "HTTP/Request.php";

$req =& new HTTP_Request("http://upload.example.com/upload.php");
$req->setBasicAuth("johndoe""foo");
$req->setMethod(HTTP_REQUEST_METHOD_POST);

$result $req->addFile('file_upload_field''/home/johndoe/text.pdf''application/pdf');
if (
PEAR::isError($result)) {
    echo 
$result->getMessage();
} else {

    
$response $req->sendRequest();

    if (
PEAR::isError($response)) {
        echo 
$response->getMessage();
    } else {
        echo 
$req->getResponseBody();
    }
}
?>
previousCookies (Previous) (Next) Request headersnext

Download Documentation Last updated: Sun, 28 Jun 2009
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
There are no user contributed notes for this page.