PHP Classes
Icontem

File: example_2.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Nashruddin Amin  >  Hacker's HTTP Client  >  example_2.php  
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
 

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";
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products