Send an image through curl
Try to send the file via curl
$file = array('file' => "@".realpath('my.jpg').";type=image/jpeg" );
$test = curlPOST($file, "http://site.ru/upload/", "http://site.ru", "c.txt" ,'', 60, 1);
echo $test;
function curlPOST($post_data, $url, $referrer='', $cookie_file='', $proxy='', $timeout=60, $header=0) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, "Opera/9.10 (Windows NT 5.1; U; en)");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_ENCODING,'gzip,deflate');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: image/jpeg'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
if($referrer) curl_setopt($ch, CURLOPT_REFERER, $referrer);
if($header) curl_setopt($ch, CURLOPT_HEADER, 1);
if($proxy) {curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, "user:pass");
//curl_setopt($ch, CURLOPT_PROXYAUTH, 1);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if($cookie_file) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
}
$content=curl_exec($ch);
curl_close($ch);
return $content;
}
In response, we get a white screen if it is sent without :; type = image / jpeg. I am getting an error that the file cannot be downloaded. On-site loading happens via ajax. The image is also a valid cookie. What am I doing wrong?
+3
source to share