简体   繁体   中英

Send a image via curl

Try to send a 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 return get a white screen, if sent without a ;type=image/jpeg I get the error message that the file cannot be loaded. At the site of loading occurs via ajax. The image is a file with the right cookies too. What am I doing wrong ?

我认为它的服务器http://site.ru/http://site.ru/upload/都给了空白屏幕

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM