尝试通过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;
}
作为回报获得一个白色屏幕,如果没有发送; type = image / jpeg我收到错误信息,说明该文件无法加载。在加载的位置通过ajax发生。该图像也是具有正确cookie的文件。我做错了什么?