PHP – File Upload Stream

On March 17, 2010, in CakePHP, Fedora, Linux, PEAR, PHP, Tips, Tricks, Web Application, by phpsolutions
File Upload Stream

File Upload Stream

PHP supports upload file stream… we can stream data to server using PHP stream_open() & stream_write() functions.

There is alternate method in PEAR to transfer files to server1 to server2. PEAR have HTTP package for uploading files.

HTTP_Request supports GET/POST/HEAD/TRACE/PUT/DELETE, Basic authentication, Proxy, Proxy Authentication, SSL, file uploads etc.

<?php
require_once "HTTP/Request.php";
$req =& new HTTP_Request("http://domain.com/upload");
$req->setBasicAuth("login", "pass");
$req->setMethod(HTTP_REQUEST_METHOD_POST);

$result = $req->addFile("data", "/home/phpsolutions.mp4");
if (PEAR::isError($result)) {
echo "Error occurred during file upload!";
} else {
$response = $req->sendRequest();
if (PEAR::isError($response)) {echo "Error occurred during file upload!";
} else {
echo "File successfully uploaded!";
}
}
?>

5 Responses to PHP – File Upload Stream

  1. Anonymous says:

    I am really thankful towards the author in this post for making this lovely and informative article live to put us. We really appreciate ur effort. Maintain the nice work. . . .

  2. Virgil Grenko says:

    I thought this was a fantastic blog, not only great writing but it has a great layout, well done.

  3. Anonymous says:

    great site, i really liked reading this article. will come back for more.

  4. Anonymous says:

    Hi,thanks for the vast status of your blog, each outmoded i total here, i m amazed.

  5. Anonymous says:

    It’s super blog, I want to be like you

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.