
CURLFile::setPostFilename 메서드는 HTTP 요청의 파일 필드에 포함될 파일 이름을 지정하는 역할을 합니다. 이 메서드는 파일 이름을 지정할 때, 파일 이름 자체를 포함하는 것이 아니라, 파일 이름을 포함하는 HTTP 요청의 Content-Disposition 헤더를 생성하는 것입니다.
예를 들어, CURLFile::setPostFilename 메서드를 사용하여 "example.txt"라는 파일 이름을 지정하면, HTTP 요청의 Content-Disposition 헤더에 "filename=\"example.txt\""라는 값이 포함됩니다. 이 헤더는 HTTP 요청의 파일 필드에 포함되는 파일 이름을 지정하는 역할을 합니다.
다음은 예제 코드입니다.
#hostingforum.kr
php
$file = new CURLFile('example.txt', 'text/plain');
$file->setPostFilename('example.txt');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/upload');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => $file));
$response = curl_exec($ch);
curl_close($ch);
위 코드에서, CURLFile::setPostFilename 메서드는 HTTP 요청의 Content-Disposition 헤더에 "filename=\"example.txt\""라는 값을 포함시킵니다. 이 값은 HTTP 요청의 파일 필드에 포함되는 파일 이름을 지정하는 역할을 합니다.
2025-03-27 14:49