Skip to content
WJunction - Webmaster Forum

Upload image to PixHost

Status
Not open for further replies.

3 comments

PHP:
function upload_to_pixhost($img,$safe=0) {
    
    $imageUrl = '';
    $pvars = array('img[]'=>"@".$img,'content_type'=>$safe,'tos'=>'on');
    $page = get_page('http://www.pixhost.org/classic-upload/',$pvars,'','http://www.pixhost.org/classic-upload/');
    //echo '<textarea>'.htmlentities($page).'</textarea>';
    preg_match('~<div class="linksleft">Forum thumbnail:</div>\s+<div class="linksright"><input type="text" style="width:500px" onclick="javascript:highlight\(this\);" readonly="readonly" value="(.*?)"/></div>~',$page,$match);
    //print_r($match);
    $imageUrl = $match[1];
    if(stristr($imageUrl,'pixhost.org')) return $imageUrl;
    else return '';
}

$img = 'D:\Ampps\www\test\0001.jpg';
echo upload_to_pixhost($img);

a curl function you can find here: http://wscripts.net/php-snippets/get-a-page-using-curl/
 
I've resolt..

I write that code:

PHP:
$imgpath = "/some/file/in/some/directory.jpg"

$agent= "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14"; 

$reffer= "http://www.pixhost.org/classic-upload/"; 
$cookie_file_path = 'files/cookie.txt'; 
$fp1 = fopen($cookie_file_path,'wb');    
if(!$fp1) 
echo 'error opening cookie file'; 
fclose($fp1); 

$ch1 = curl_init(); 
curl_setopt($ch1, CURLOPT_URL,"http://www.pixhost.org:8080/classic-upload/"); 
curl_setopt($ch1, CURLOPT_USERAGENT, $agent); 
curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt($ch1, CURLOPT_COOKIEJAR, $cookie_file_path); 
curl_setopt($ch1, CURLOPT_REFERER, ""); 
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 1); 
$html1 = curl_exec($ch1); 


$ch1 = curl_init(); 
curl_setopt($ch1, CURLOPT_URL, 'http://www.pixhost.org:8080/classic-upload/"'); 
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch1, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch1, CURLOPT_REFERER,$reffer); 
curl_setopt($ch1, CURLOPT_POST, 1); 
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
// curl_setopt($ch, CURLOPT_COOKIESESSION, true); 
curl_setopt($ch1, CURLOPT_USERAGENT, $agent);         
curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt($ch1, CURLOPT_COOKIEJAR, $cookie_file_path); 
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION,1); 
$postResult = curl_exec($ch1); 



$data1 = array('content_type' => '1', 'img[]' => '@'.$imgpath,'tos'=>'on'); 
curl_setopt($ch1, CURLOPT_URL, 'http://www.pixhost.org:8080/'); 
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch1, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch1, CURLOPT_REFERER,'http://www.pixhost.org:8080/classic-upload/'); 
curl_setopt($ch1, CURLOPT_POST, 1); 
curl_setopt($ch1, CURLOPT_POSTFIELDS, $data1); 
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch1, CURLOPT_COOKIESESSION, true); 
curl_setopt($ch1, CURLOPT_USERAGENT, $agent);         
curl_setopt($ch1, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt($ch1, CURLOPT_COOKIEJAR, $cookie_file_path); 
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION,1); 
$postResult = curl_exec($ch1); 

if (curl_errno($ch1)) { 
print curl_error($ch1); 
} 
curl_close($ch1); 
//print $postResult
preg_match('~<div class="linksleft">HTML thumbmail:</div>\s+<div class="linksright"><input type="text" style="width:500px" onclick="javascript:highlight\(this\);" readonly="readonly" value="(.*?)"/></div>~',$postResult,$match);
    //print_r($match);
    $imageUrl = $match[1];
   if(stristr($imageUrl,'pixhost.org')) echo $imageUrl;
    else return '';

It saves HTML thumbmail, it seems works well :)
 
Status
Not open for further replies.

About the author

S
Experienced Member · Joined
741
Messages
59
Reactions
28
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom