Заливка файлов на радикал PHP

Фев 26

Если нет желания забивать сервер картинками, то данный скриптец поможет. Он грузит картинку с веба (урл) на радикал, возвращает адрес картинки на радикале.

$postdata = "upload=yes&F=&URLF=".$imagelink."&O=yes&M=640&JQ=85&J=yes&IM=7&VM=180&R=0&VE=yes&V=Увеличить&X=&FS=";
$page = FetchUrl("http://www.radikal.ru/action.aspx", $postdata, NULL, NULL, NULL);
preg_match("!id=\"input_link_1\" value=\"(.*?)\"!si", $page, $imageUrl);
$imageUrl = $imageUrl[1];

FetchUrl моя универсальная функция для курла, я ее под все подряд юзаю, поэтому там много левого кода. При желании можно поудалять половину.

function FetchUrl($url, $postvars, $timeout, $ref, $blank){
 sleep($timeout);                         
 echo @date("r")." fetching $url\r\n";              
 $ch = curl_init();   
 if(isset($postvars)){
 echo @date("r")." $postvars\r\n";                    
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
 }
//        curl_setopt($ch, CURLOPT_PROXY, $proxy);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);       
//        curl_setopt($ch, CURLOPT_HEADER, true);           
 curl_setopt($ch, CURLOPT_TIMEOUT,15);               
 curl_setopt($ch, CURLOPT_ENCODING, 'gzip');         
 curl_setopt($ch, CURLOPT_COOKIEJAR, "c1.txt");    
 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux x86_64; ru; rv:1.9.1.6) Gecko/20091201 SUSE/3.5.6-1.1.1 Firefox/3.5.6 FirePHP/0.3");     
 curl_setopt($ch, CURLOPT_COOKIEFILE, "c1.txt");     
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);  
 curl_setopt($ch, CURLOPT_URL, trim($url));
 curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
 curl_setopt($ch, CURLOPT_REFERER, $ref);                                                                  
 $result = curl_exec($ch);     
 if($blank == "1"){    
     $result = preg_replace("/\n/", "", $result);
     $result = preg_replace("/\r/", "", $result);
 }
 curl_close($ch);                                                                                        
 return $result;                                                                                              
 }

FTP + CURL

Янв 10

Пара способов, загрузить файлы на фтп при помощи курла.
Первый, самый простой и расово верный:

curl -v -T filename ftp://login:password@ftp.site.ru

Второй, немного побольше, при помощи php

function UploadFTP($ftpLogin, $ftpPass, $ftpAddr, $ftpFile){
 $remoteurl = "ftp://${ftpLogin}:${ftpPass}@${ftpAddr}${ftppath}/${ftpFile}";
 $ch = curl_init();
 $fp = fopen($ftpFile, "rb");
 curl_setopt($ch, CURLOPT_URL, $remoteurl);
 curl_setopt($ch, CURLOPT_UPLOAD, 1);
 curl_setopt($ch, CURLOPT_INFILE, $fp);
 curl_setopt($ch, CURLOPT_INFILESIZE, filesize($ftpFile));
 $error = curl_exec($ch);
 curl_close($ch);
 return $error;
}

Загрузка изображений на imageshost по курлу

Сен 16

Загружает по курлу указанный урл (грузит с веба, не с локального компа), возвращает ссылку на картинку.

function UploadImage($iurl){
 echo date("r")." fetching $url\r\n";
 echo date("r")." sending $postvars\r\n";
 $ch = curl_init();
 $postvars = "type=3&qnt=1&isurl=1&userimg1=$iurl&to_size_w=&to_size_h=&to_angle=0&pvs1=350&quality=100&pr_text=Увеличить&text=description=rules=on&submit_button=Загрузить";
curl_setopt($ch, CURLOPT_POST      ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS    , $postvars);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
curl_setopt($ch, CURLOPT_HEADER      ,1);
curl_setopt($ch, CURLOPT_TIMEOUT,15);
//    curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_COOKIEJAR, "c1.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "c1.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "http://imageshost.ru/upload.php");
curl_setopt($ch, CURLOPT_USERAGENT, "Firefox/3.0");
$result = curl_exec($ch);
curl_close($ch);
preg_match("!img=(.*?)\]!i", $result, $out);
$result = $out[0];
return $result;
}

Постим в твиттер через курл

Июл 08

Можно интегрировать в свой блог, и пост автоматом уйдет в твиттер, можно встроить в админку и писать в твиттер из админки вп. Применений масса.

<?php
// Set username and password
$username = 'username';
$password = 'password';
// The message you want to send
$message = 'is twittering from php using curl';
// The twitter API address
$url = 'http://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'http://twitter.com/statuses/update.json';
// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
// check for success or failure
if (empty($buffer)) {
echo 'message';
} else {
echo 'success';
}
?>

Пример простой спамилки вордпресса

Июл 07

У курла есть много вариантов использования )

<?php
$postfields = array();
$postfields["action"] = "submit";
$postfields["author"] = "Spammer";
$postfields["email"] = "spammer@spam.com";
$postfields["url"] = "http://www.iamaspammer.com/";
$postfields["comment"] = "I am a stupid spammer.";
$postfields["comment_post_ID"] = "123";
$postfields["_wp_unfiltered_html_comment"] = "0d870b294b";
//Url of the form submission
$url = "http://www.ablogthatdoesntexist.com/blog/suggerer_site.php
?action=meta_pass&id_cat=0";
$useragent = "Mozilla/5.0";
$referer = $url;

//Initialize CURL session
$ch = curl_init($url);
//CURL options
curl_setopt($ch, CURLOPT_POST, 1);
//We post $postfields data
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
//We define an useragent (Mozilla/5.0)
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
//We define a refferer ($url)
curl_setopt($ch, CURLOPT_REFERER, $referer);
//We get the result page in a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//We exits CURL
$result = curl_exec($ch);
curl_close($ch);

//Finally, we display the result
echo $result;
?>

Доки по курлу

Июл 07

Оч полезный ман по курлу, можно много дел сделать не выходя из консоли.
Например залить файл

curl -T uploadfile www.uploadhttp.com/receive.cgi

http://rus-linux.net/MyLDP/internet/curlrus.html
Читать строго под такую музыку!

Kiborg – Бодрячком (Сява-кавер)

Пишем в вордпресс через curl

Июл 06

Данной функцией можно постить в вп.

function wpPostXMLRPC($title,$body,$rpcurl,$username,
$password,$category,$keywords='',$encoding='UTF-8')
{
$title = htmlentities($title,ENT_NOQUOTES,$encoding);
$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);

$content = array(
'title'=>$title,
'description'=>$body,
'mt_allow_comments'=>0,  // 1 to allow comments
'mt_allow_pings'=>0,  // 1 to allow trackbacks
'post_type'=>'post',
'mt_keywords'=>$keywords,
'categories'=>array($category)
);
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);
return $results;
?>