2

現在これを使用していますが、保存されているファイルが空なので、データが通っていないと思います。

$post = array("file"=>'@'.$_FILES['uploadfile']['tmp_name']);         
$ch = curl_init();
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Parse-Application-Id : XXXXXXXXXXXXXX','X-Parse-REST-API-Key: XXXXXXXXx', 'Content-type: image/jpeg'));
curl_setopt($ch, CURLOPT_URL, 'https://api.parse.com/1/files/'.$_FILES['uploadfile']['name']);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
4

2 に答える 2

7

動作しました。バイナリデータを投稿フィールドとして送信する必要があります。当たり前。この前に、おそらくいくつかの制限(ファイルサイズ、タイプなど)を作成する必要があります

$post = file_get_contents($_FILES['uploadfile']['tmp_name']);

$ch = curl_init();
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Parse-Application-Id : XXXXXXXX','X-Parse-REST-API-Key: XXXXXXXXXXXXXXX', 'Content-type: image/jpeg'));
curl_setopt($ch, CURLOPT_URL, 'https://api.parse.com/1/files/'.$_FILES['uploadfile']['name']);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
于 2012-07-09T04:29:13.287 に答える
1

私たちが必要としているのとまったく同じように、この作品を使用してください.....

function sendImageToParse($url, $filename) {
    $this->layout = FALSE;
    $this->autoRender = false;

    $headers = array(
        'X-Parse-Application-Id:' . $this->APPLICATION_ID,
        'X-Parse-REST-API-Key:' . $this->REST_API_KEY,
        'Content-Type: image/jpeg'
    );

    $data = file_get_contents($url);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_URL, 'https://api.parse.com/1/files/' . $filename);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}

function add() {

    if ($this->request->is('post')) {

        $giftUniqueId = time();
        $urlFileImage = $allData['Coupon']['imageLink']; 
        //Eg : "http://localhost/favrapp/img/couponsLogo/gap.jpg";
        $filename = $allData['Coupon']['imageName']; //Eg : "gap.jpg";

        $responseFile = $this->sendImageToParse($urlFileImage, $filename);
        $arrayInt = json_decode($responseFile);

        if (!empty($arrayInt)) {
            $name = $arrayInt->name;
            $url = $arrayInt->url;
        } else {
            $name = '';
            $url = '';
        }

        //Save to table by creating object   
        $url = 'https://api.parse.com/1/classes/giftcard';
        $data = array('name' => $allData['Coupon']['name'], 
               'couponType' => $allData['Coupon']['coupontype'],
               'giftcardTypeid' => $allData['Coupon']['giftcardTypeid'], 'giftcardcheckid' => $giftUniqueId,
            'logo' => array('name' => $name, '__type' => 'File', 'url' => $url),
        );
        $_data = json_encode($data);
        $headers = array(
            'X-Parse-Application-Id: ' . $this->APPLICATION_ID,
            'X-Parse-REST-API-Key: ' . $this->REST_API_KEY,
            'Content-Type: application/json',
            'Content-Length: ' . strlen($_data),
        );

        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $_data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_exec($curl);
        curl_close($curl);
    }

}
于 2015-09-23T10:30:00.773 に答える