Php 通过curl发送图像

Php 通过curl发送图像,php,curl,Php,Curl,尝试通过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_fi

尝试通过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进行加载。图像也是一个包含正确cookies的文件。我做错了什么?

我认为是服务器和所有屏幕都是空白的

删除MIME类型并出现“未找到文件”错误的事实向我表明文件名/文件路径有问题。仔细检查它是否在正确的位置。我已尝试指定完整路径,文件完全正确。例如:“@C:\\AppServ\\www\\test\\1.jpg”,因此作为响应,我得到了未加载的文件,如果您将minetype添加到文件中,则curl错误-创建formpost数据失败。我尝试复制您的代码并上载到我自己的Web服务器,并且它工作正常。我正在使用OSX,但我会看看你的文件名的不同选项。您要上载到的服务器也可能有问题?请在您的linux服务器上再试一次,它无法工作。这里的http转储看起来像是live http头中的查询—我首先得到的键的值,看起来它正在工作。它正在发送9831字节,并获得200个响应代码。是什么让你相信这是行不通的?