# phpでの画像データをアップロードについて

**URL:** <https://community.cybozu.dev/t/topic/6595>\
**Category:** kintone 開発相談\
**Created:** [2020 年 8 月 6 日午前 4:55 UTC](https://community.cybozu.dev/t/topic/6595 "2020-08-06T04:55:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account2353](https://avatars.discourse-cdn.com/v4/letter/l/7feea3/32.png) [@Legacy\_Account2353](https://community.cybozu.dev/u/Legacy_Account2353)\
**Post date:** [2020 年 8 月 6 日午前 4:55 UTC](https://community.cybozu.dev/t/topic/6595/1 "2020-08-06T04:55:52Z")

</div>

**実現したいこと**

wordpressのお問い合わせフォーム（画像ファイルあり）の内容をkintoneに登録したいと考えたいます。

テキスト情報のkintoneへの登録はできるのですが、画像ファイルのアップロードが上手くいきません。

解決策がわかる方がいっらしゃいましたらご教授ください。

&nbsp;

**エラー情報**

{“code”:“GAIA\_HM02”,“id”:“9Zb9xmZizjUModDZdGMd”,“message”:“アップロードするHTTPリクエストの形式が正しくありません。HTTPリクエストはマルチパート形式である必要があります。”

**利用したソースコード**

&nbsp;

// APIトークン（アプリ設定画面で発行）

define(“API\_TOKEN”, “xxxxxxxxxxxxxxxxxxxxxx”);

// サブドメイン

define(“SUB\_DOMAIN”, “xxxxxxxxxxxxxxxxxxxxxx”);

// アプリID

define(“APP\_NO”, “xxx”);

// -------------- kintoneへの登録処理 --------------

$fileUploadHeaders = array(

&nbsp; &nbsp; &nbsp; “X-Cybozu-API-Token:”.API\_TOKEN,

&nbsp; &nbsp; &nbsp; “contentType: multipart/form-data; boundary=------111111111-------”,

);

&nbsp;

&nbsp;

$file\_path = $\_FILES[‘main-img’][‘tmp\_name’];

$file\_type = $\_FILES[‘main-img’][‘type’];

$file\_name = $\_FILES[‘main-img’][‘name’];

&nbsp;

// cURLセッションを初期化する

$curlUploadFile = curl\_init(‘https://’. SUB\_DOMAIN .‘.cybozu.com/k/v1/file.json’);

// cURLの通信オプションを設定

// メソッド名指定 :HTTP POST

curl\_setopt($curlUploadFile, CURLOPT\_CUSTOMREQUEST, “POST” );

// curl\_exec()を実行時、返り値を文字列で返す

curl\_setopt($curlUploadFile, CURLOPT\_RETURNTRANSFER, true);

// ヘッダー設定

curl\_setopt($curlUploadFile, CURLOPT\_HTTPHEADER, $fileUploadHeaders);

// メソッド名指定 :HTTP POST

curl\_setopt($curlUploadFile, CURLOPT\_POST, true);

// CURLFileオブジェクトの作成 Curlでファイルをアップロードする為に必要 必要なパラメータ: ファイルのパス,ファイルの Mimetype,ファイル名

$file = curl\_file\_create( $file\_path, $file\_type, $file\_name);

//HTTP “POST” で送信するすべてのデータ設定

curl\_setopt($curlUploadFile, CURLOPT\_POSTFIELDS, array(‘file’ =\> $file));  
// 実行

$uploadFileRes = curl\_exec($curlUploadFile);

// cURLセッションを終了する

curl\_close($curlUploadFile);

&nbsp;

&nbsp;
