CURLFile::__construct

curl_file_create

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

CURLFile::__construct -- curl_file_create — Створює об'єкт CURLFile

Опис

Об'єктно-орієнтований стиль

public CURLFile::__construct(string$filename, ?string$mime_type null, ?string$posted_filename null) .

Процедурний стиль

curl_file_create(string $filename, ?string $mime_type = null, ?string $posted_filename = null): CURLFile

Створює об'єкт CURLFile, що використовується для завантаження файлу з використанням опції CURLOPT_POSTFIELDS

Список параметрів

filename

Шлях до файлу, який буде завантажено

mime_type

Mime-тип файлу.

posted_filename

Ім'я файлу при надсиланні методом POST.

Значення, що повертаються

Повертає об'єкт типу CURLFile

список змін

ВерсияОпис
8.0.0mime_typeиposted_filename тепер припускають значення null; раніше значенням за умовчанням був

Приклади

Приклад #1 Приклад використання CURLFile::__construct()****

Об'єктно-орієнтований стиль

Loading...

Процедурний стиль

Loading...

Результат виконання наведеного прикладу:

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)
  }
}

Приклад #2 Приклад використання CURLFile::__construct()** для завантаження кількох файлів**

Об'єктно-орієнтований стиль

Loading...

Процедурний стиль

Loading...

Результат виконання наведеного прикладу:

array(26) {
  ["url"]=>
  string(31) "http://www.example.com/upload.php"
  ["content_type"]=>
  string(24) "text/html; charset=UTF-8"
  ["http_code"]=>
  int(200)
  ["header_size"]=>
  int(198)
  ["request_size"]=>
  int(196)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.060062)
  ["namelookup_time"]=>
  float(0.028575)
  ["connect_time"]=>
  float(0.029011)
  ["pretransfer_time"]=>
  float(0.029121)
  ["size_upload"]=>
  float(3230730)
  ["size_download"]=>
  float(811)
  ["speed_download"]=>
  float(13516)
  ["speed_upload"]=>
  float(53845500)
  ["download_content_length"]=>
  float(811)
  ["upload_content_length"]=>
  float(3230730)
  ["starttransfer_time"]=>
  float(0.030355)
  ["redirect_time"]=>
  float(0)
  ["redirect_url"]=>
  string(0) ""
  ["primary_ip"]=>
  string(13) "0.0.0.0"
  ["certinfo"]=>
  array(0) {
  }
  ["primary_port"]=>
  int(80)
  ["local_ip"]=>
  string(12) "0.0.0.0"
  ["local_port"]=>
  int(34856)
}

Дивіться також

  • curl_setopt() - Встановлює параметр для передачі cURL