cURL CURLStringFile::__construct
(PHP 8 >= 8.1.0)
CURLStringFile::__construct — CURLStringFile 객체 생성
설명
public CURLStringFile::__construct(string $data
, string $postname
, string $mime
= "application/octet-stream")
CURLOPT_POSTFIELDS
를 사용하여 파일을 업로드하는 데 사용되는 CURLStringFile 개체를 만듭니다.
매개변수
data
- 업로드할 내용입니다.
postname
- 업로드 데이터에 사용할 파일의 이름입니다.
mime
- 파일의 MIME 유형입니다(기본값은
application/octet-stream
).
Examples
예제 #1 CURLStringFile::__construct() 예제
<?php
/* http://example.com/upload.php:
<?php
var_dump($_FILES);
var_dump(file_get_contents($_FILES['test_string']['tmp_name']));
?>
*/
// Create a cURL handle
$ch = curl_init('http://example.com/upload.php');
// Create a CURLStringFile object
$cstringfile = new CURLStringFile('test upload contents','test.txt','text/plain');
// Assign POST data
$data = array('test_string' => $cstringfile);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Execute the handle
curl_exec($ch);
?>
위의 예는 다음을 출력합니다.
array(1) { ["test_string"]=> array(5) { ["name"]=> string(8) "test.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpTtaoCz" ["error"]=> int(0) ["size"]=> int(20) } } string(20) "test upload contents"
기타
- curl_setopt() - cURL 전송 옵션 설정