English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP基本教程

PHP上級教程

PHP & MySQL

PHPリファレンスマニュアル

PHP curl_file_create()関数の用法と例

PHP CURLリファレンスマニュアル

(PHP 5 >= 5.5.0)

curl_file_create — CURLFileオブジェクトを作成します。

構文

CURLFile curl_file_create ( string $filename [, string $mimetype [, string $postname ]])

アップロードファイル用にCURLFileオブジェクトを作成します。

パラメータ

filename

アップロードファイルのパス

mimetype

ファイルのMIMEタイプ

postname

ファイル名。

返り値

CURLFileオブジェクトを返します。

オンラインサンプル

curl_file_create()の例

<?php
/* http://example.com/upload.php:
<?php var_dump($_FILES); ?>
*/
// CURLハンドルの作成
$ch = curl_init('http://example.com/upload.php');
// CURLFileオブジェクトの作成
$cfile = curl_file_create('cats.jpg','image/jpeg','test_name');
// POSTデータの設定
$data = array('test_file' => $cfile);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// ハンドルの実行
curl_exec($ch);
?>

以下の例では、次のように出力されます:

array(1) {
  ["test_file"]=>
  array(5) {
    ["name"]=>
    string(9) "test_name"
    ["type"]=>
    string(10) "image/jpeg"
    ["tmp_name"]=>
    string(14) "/tmp/phpPC9Kbx"
    ["error"]=>
    int(0)
    ["size"]=>
    int(46334)
  }
}

PHP CURLリファレンスマニュアル