PHP curl_file_create関数

PHP Calendar 参考手册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 Calendar 参考手册PHP cURL リファレンスマニュアル

その他の拡張モジュール