Do you guys knows skyrock dot com? or any of those networks... im trying to upload a photo with curl to put like a service in my website.
Anyway this is what i tried so far:
<?
//-- REQUEST FUNC
function MakeRequest($url= NULL, $reffer = NULL, $POSTFIELDS = NULL) {
$url = $url;
$reffer = $reffer;
$cookie_file_path = 'cookie';
$header_array[0] = "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-AR; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11";
$header_array[1] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*;q=0.5";
$header_array[2] = "Accept-Language: es-ar,es;q=0.8,en-us;q=0.5,en;q=0.3";
$header_array[3] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header_array[4] = "Accept-Encoding: gzip, deflate";
$ch = curl_init();
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_ENCODING,"gzip, deflate");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,7);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch,CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
//-- LOGIN FUNC
function Login($user,$pass)
{
$url = 'http://www.skyrock.com/m/account/login.php';
$reffer = 'http://www.skyrock.com/m/account/login.php';
$POSTFIELDS = 'need_login_form_login='.$user.
'&need_login_form_password='.$pass;
$request = MakeRequest($url, $reffer, $POSTFIELDS);
if(stristr($request, "Log out")) {
$loggedin = '1';
} else {
$loggedin = '0';
}
return $loggedin;
}
//-- UPLOAD FUNC
function Photo($postdata){
$url = 'http://www.skyrock.com/profil/admin/photos.php';
$reffer = 'http://www.skyrock.com/profil/admin/photos.php';
//-- POSTFIELDS
$contentfile = join("", file('1.jpg'));
/*$postdata = '-----------------------------310841564872176
Content-Disposition: form-data; name="photo"; filename="1.jpg"
Content-Type: image/jpeg
'.$contentfile.'
-----------------------------310841564872176
Content-Disposition: form-data; name="legend"
-----------------------------310841752016616
Content-Disposition: form-data; name="avatar"
1
-----------------------------310841564872176--
';*/
//-- POSTFIELDS
$photo = MakeRequest($url,$reffer,$postdata);
return $photo;
}
//-- LOGIN
$user = '123456a4fsd';
$pass = '123456';
$login = Login($user,$pass);
if($login == 1){
//-- POSTFIELDS ARRAY
$file = '1.jpg';
$postdata[photo][name] = @$file;
$postdata[photo][type] = 'image/jpeg';
$postdata[photo][tmp_name] = 'php3F.tmp';
$postdata[photo][size] = '11202';
$postdata[photo][error] = '0';
$postdata[legend] = 'me';
$postdata[avatar] = '1';
//-- UPLOAD PIC
echo $photo = Photo($postdata);
} else {
echo 'Can\'t login';
exit;
}
?>
Im don't really know how to hangle multipart forms, is the first time i try and i'm just getting the page as result, without any error.
Does anyone knows how to get this image upload working?
if someone want to test, in the function i put my login info, plz don't be funny and change the pass i'm using it for testing.
Thnkx in advance.