...

View Full Version : curl help for img



Dshah
03-04-2010, 09:07 AM
I hope i can get help here, i am not good in curl and trying to write a function which will upload an image to a free imagehost, Currently what this script does is it will go to the site and try to post the image but it always get reply:

"Upload is disabled during short maintenance work (ETA 10 minutes). Brb!".

but if i add image from my computer without using this script it is working normally, i need to run this script stand alone, so when i open the file it will run the script, here is the code i am trying to use,

<?php
set_time_limit(0);
session_start();


$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 = 'cookie.txt';
$fp = fopen($cookie_file_path,'wb');
if(!$fp)
echo 'error opning cookie file';
fclose($fp);



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


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



$data = array('content_type' => '1', 'image[]' => '@image.gif');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.pixhost.org:8080/java.php"');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_REFERER,'http://www.pixhost.org:8080/classic-upload/');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
$postResult = curl_exec($ch);

if (curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
print $postResult ;

?>

i have an image named "image.gif" in same folder when i run this file, please if you can run the script once you will see what i mean, Please can some one help me sort this i really appreciate and hope this community can help me,

Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum