You're here: Home / PHP /

Upload and Download Files Over HTTP with PHP

These functions are used to upload and download files over HTTP. It opens socket connection to the remote host and make HTTP requests. Use these functions to easily upload and download files within your PHP code.

Features:

  • No dependencies
  • Upload and download any files
  • Easy to use
  • Easy to customize

Usage:

1. download file http://www.example.com/path/spec.pdf and save to C:/tmp/spec2.pdf

$remote = "http://www.example.com/path/spec.pdf";
$local  = "C:/tmp/spec2.pdf";
$res = get_file($remote, $local);
if (!$res) {
    print "something went wrong";
    exit;
}
print "file saved.";

2. Simulate HTML form to upload a file

/*
 * the code below simulate HTML form like this:
 *
 * <form enctype="multipart/form-data" action="http://www.example.com/upload.php" method="post">
 * <input type="file" name="image">
 * <input type="submit">
 * </form>
 *
 * the file http://www.example.com/upload.php should be able to process the incoming file. 
 * maybe something like this:
 *
 * <?php
 * move_uploaded_file($_FILES['image']['tmp_name'], $_FILES['image']['name']);
 * ?>
 */
$filename = "C:/tmp/photo.jpg";
$handler  = "http://www.example.com/upload.php";
$field    = "image";

$res = send_file($filename, $handler, $field);

if ($res) {
    echo "file sent.";
} else {
    echo "something went wrong.";
}?>

Keywords: php uploader, php downloader, simulate post form, http file transfer, upload and download files over HTTP

Share:  del.icio.us logo Save to del.icio.us  digg logo Digg this!

comment.gifComments

Thank you for script. I like it!

Awesome

i like it

comment.gifAdd your comment

(required, will not be published) (optional)