PHP Classes

File: example_2.php

Recommend this page to a friend!
  Classes of Nashruddin Amin   Hacker's HTTP Client   example_2.php   Download  
File: example_2.php
Role: Example script
Content type: text/plain
Description: Upload images to TinyPic.com and retrieve the URLs
Class: Hacker's HTTP Client
Automate retrieval and processing of Web pages
Author: By
Last change:
Date: 15 years ago
Size: 1,092 bytes
 

Contents

Class file image Download
<?php
/**
 * Uploading image to tinypic.com and retrieve the image's URL
 */
include 'phpWebHacks.php';

$h = new phpWebHacks;

/* tinypic.com */
$h->get('http://tinypic.com');

/* get the hidden fields */
$form = $h->parseForm('uploadform', &$action);

/* filetype = image, resize = default */
$form['file_type'] = 'image';
$form['dimension'] = '1600';

/* 'browse' the image to upload */
$file = array('the_file' => '/home/nash/elvita.jpg');

/* submit */
$page = $h->post($action, $form, $file);

/* It will show a 'click here to view the image' page
   and then redirects using javascript.
   Since javascript is not supported, we need to manually
   parse the URL */
preg_match('/<a\s+href\s*=\s*"(.+)".*>/iU', $page, $url);

/* get the result page */
$h->get($url[1]);

/* and here are the URLs */
$form = $h->parseForm('email_form');
echo
"HTML Code : " . $form['html-code'] . "\n";
echo
"Forums : " . $form['img-code'] . "\n";
echo
"Email : " . $form['email-url'] . "\n";
echo
"Direct link : " . $form['direct-url'] . "\n";
?>