PEAR Manual
Prev |  | Next

# File uploads

File uploads -- Uploading files via HTTP

## How to use file uploads

Example 42-1. Upload a PDF document In this example a file named `/home/johndoe/text.pdf` is uploaded to the remote machine `upload.example.com` under the name `johndoe-text.pdf`. Additionally Basic Authentication is used to ensure that John is allowed to upload something.
    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("johndoe-txt.pdf", "/home/johndoe/text.pdf");
    if (PEAR::isError($result)) {
        echo $result->getMessage();
    } else {

        $response = $req->sendRequest();

        if (PEAR::isError($response)) {
            echo $response->getMessage();
        } else {
            echo $req->getResponseBody();
        }
    }

Prev | Home | Next
Cookies | Up | Request headers